'Stuck on twitter redirect page when trying to save credentials
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.
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ranvir Choudhary |
