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
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.
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.