Install got
and oauth-1.0a
NPM dependencies.
import { TwitterClient } from "./twitter";
// Initializes a new Twitter client using OAuth 1.0a credentials
const twitter = new TwitterClient({
// Twitter App credentials (API key and secret)
// https://developer.twitter.com/en/portal/projects
apiKey: env.TWITTER_API_KEY,
apiSecret: env.TWITTER_API_SECRET,
// User credentials (avaialble upon sign in)
userToken: "xxxxx",
userSecret: "xxxxx",
});
// Posts a new tweet to the user's timeline
const tweet = await twitter.post({
text: "Hello"
});