1

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);
at.
  • 50,922
  • 104
  • 292
  • 461
  • 2
    Using [V1.1 or V2 API](https://developer.twitter.com/en/docs/twitter-api/migrate/twitter-api-endpoint-map) directly, it is much more documented and can use most of the capabilities. – Bench Vue Mar 16 '23 at 01:47

0 Answers0