Just to clarify, i’m not providing a service, so i am not using sessions

i’m trying to save my tokens in a file and access them in another.

i’m using the twitter-api-v2 package.

here is a part of my oauth file

client
    .login(oauth_verifier)
    .then(({ client: loggedClient, accessToken, accessSecret }) => {
      let tokens = {
        accessToken: accessToken,
        accessSecret: accessSecret,
        oauth_verifier: oauth_verifier
      };
      fs.writeFileSync("./tokens.json", JSON.stringify(tokens), (err) => console.error(err));
      res.status(200).send("success")
    })
    .catch((err) => {
      console.log(console.error(err))
      res.status(403).send("Invalid verifier or access tokens!")
    });

i am setting the oauth_token_secret manually.

now when i run the code for my bot, which is here

const tokens = JSON.parse(fs.readFileSync("./tokens.json"));

const { accessToken, accessSecret, oauth_verifier } = tokens;

const client = new TwitterApi({
  appKey: process.env.API_KEY,
  appSecret: process.env.API_KEY_SECRET,
  accessToken: accessToken,
  accessSecret: accessSecret,
});

const {client: Bot} = await client.login(oauth_verifier);
// i believe the line above is throwing me the erorr

//if i try to tweet here, using the Bot.v2.tweet() method here doesn't work

i have logged out all of my credentials, and they are what i can see in the JSON file.

Is my authLink.oauth_token supposed to match the one i write in my file? do they change every time i click the authLink? because if they do change everytime i click the auth link, my tokens dont update, but my oauth_verifier does in my JSON file

1 Like

I am having the same issue, not entirely clear to me why there are so many token/secret pairs. consumer token, client token, api token, access token…