I'm trying to use Twitter's official JavaScript/TypeScript SDK to post tweets on my behalf periodically. I've generated an access token and access token secret pair in their develop portal to do this. But their example code isn't clear how to authenticate like this. I have no problem authenticating with a Bearer token, but that doesn't allow me to tweet from my twitter account.
The following code uses a mechanism to prompt a user for their login, but I don't want this. I want to use my access credentials programmatically.
import { Client, auth } from "twitter-api-sdk";
// Initialize auth client first
const authClient = new auth.OAuth2User({
client_id: process.env.CLIENT_ID as string,
client_secret: process.env.CLIENT_SECRET as string,
callback: "YOUR-CALLBACK",
scopes: ["tweet.read", "users.read", "offline.access"],
});
// Pass auth credentials to the library client
const twitterClient = new Client(authClient);