You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I use sdk to post twitter with code below and I get 403 error. How could I use it correctly?
exportclassTwitterHandler{authClient: auth.OAuth2User;client: Client;agent: AgentClient;constructor(){this.authClient=newauth.OAuth2User({client_id: envConfig.X_CLIENT_ID,client_secret: envConfig.X_CLIENT_SECRET,callback: `${envConfig.SERVER_DOMAIN}/callback`,scopes: ["tweet.read","users.read","tweet.write","offline.access"],});this.client=newClient(this.authClient);this.agent=newOpenAIAgent();}asynccheckAndUpdateAccessToken() : Promise<void>{if(this.authClient.isAccessTokenExpired()){awaitthis.authClient.refreshAccessToken()}}asyncsendTweet(text: string): Promise<void>{try{letresult=awaitthis.agent.responseText(text);if(!result){thrownewError("Processed tweet text cannot be null or empty");}awaitthis.checkAndUpdateAccessToken();console.log("result",result);console.log("authClient",this.authClient)awaitthis.client.tweets.createTweet({text: result})}catch(error){console.error("Error posting tweet:",error);}}}
app.get('/auth',(req,res)=>{constauthUrl=twitterHandler.authClient.generateAuthURL({state: 'state',code_challenge_method: 'plain',code_challenge: 'challenge',});res.redirect(authUrl);});app.get('/callback',async(req,res)=>{constcode=req.query.codeasstring;console.log("before",twitterHandler.authClient)lettoken=awaittwitterHandler.authClient.requestAccessToken(code);constuserInfo=awaittwitterHandler.getAuthenticatedUserInfo();console.log(token.token)awaittwitterHandler.sendTweet("hello")if(userInfo){res.send(`Authentication successful! User ID: ${userInfo.id}, User Name: ${userInfo.name}`);}else{res.status(500).send("Error fetching user info");}});
Expected behavior
When the twitter user call /auth in the browser, and authorize to the application, then It will post a tweet.
When I use sdk to post twitter with code below and I get 403 error. How could I use it correctly?
Expected behavior
When the twitter user call
/auth
in the browser, and authorize to the application, then It will post a tweet.Actual behavior
get error with code 403, more detail in the below
The text was updated successfully, but these errors were encountered: