0

I'm using the twitter-api-v2 package and I cant save my access_token, access_token_secret and oauth_verifier. i want to save the oauth_verifier because i want to create the actual bot in another file.

Here's what I've found

  • Using writeFile throws me the error in my catch statement
  • Using writeFileSync keeps me stuck on the page, and does not write to the file
  • Trying to tweet something works, the tweet is sent in the background, but i stay stuck on the page
client
    .login(oauth_verifier)
    .then(({ client: loggedClient, accessToken, accessSecret }) => {
      let tokens = {
        accessToken: accessToken,
        accessSecret: accessSecret,
      };
      fs.writeFile("./tokens.json", JSON.stringify(tokens));
      // loggedClient.v2.tweet("hello this is test number: 3"); << this works. i stay stuck
                                                              //on the redirect page, but the tweet is sent
    })
    .catch(() => res.status(403).send("Invalid verifier or access tokens!"));

I was able to save my access_token and access_token_secret the first time i ran this code. but I cannot anymore.

I will also add, to clear any confusion, i am not providing a service. This is a bot that i am creating to practice, and i am not providing a servce. if that is relevant.

  • What are the exact errors you get? And did you check you get the 'accessToken' and 'accessSecret' as expected? – Ron Hillel May 16 '22 at 08:14
  • @RonHillel as i said, if i use writeFile(), i get the error in my .catch() method which is error 403 i also get a 404 error but i believe that's a favicon error. if i use writeFileSync() i stay stuck on the redirect page. The first time i ran the script, i did get correct `accessToken` and `accessSecret`, (at least i think i did, i cant check them now, but i'm pretty sure i did receive the correct credentials) – Ranvir Choudhary May 16 '22 at 08:20
  • Can you use 'writeFile' or 'writeFileSync' without any errors outside the twitter request? (To verify it works) – Ron Hillel May 16 '22 at 08:35
  • Hello @RonHillel i can use `writeFile` and `writeFileSync` without any issues if i execute it outside of my callback. – Ranvir Choudhary May 16 '22 at 12:32

1 Answers1

0

my issue has been resolved. Turns out, the problem was that i was not sending a success response to twitter. I just needed to send a 200 status response in my .then() where i write to my json file.