node-twitter-api-v2 icon indicating copy to clipboard operation
node-twitter-api-v2 copied to clipboard

[bug] I can't refresh tokens.

Open wholelott4 opened this issue 4 years ago • 1 comments

"twitter-api-v2": "^1.12.0", node: v16.14.2

const twitterAPI = new twitter.TwitterApi({clientId: 'ABC', clientSecret: 'DEF'}) const { twitterAPI: refreshedClient, accessToken, refreshToken: newRefreshToken } = await twitterAPI.refreshOAuth2Token(user.twitter.refreshToken);

I am receiving an 401 Unauthorized error, with the message: " Missing valid authorization header ".

the {user.twitter.refreshToken} is giving me the correct refresh token, already debugged that.

To obtain the refresh token, I am using the method loginWithOAuth2 and I get all the information correctly.

wholelott4 avatar Jun 30 '22 16:06 wholelott4

Hi,

Tested your code like this:

const credentials = {
  clientId: process.env.OAUTH2_CLIENT_ID!,
  clientSecret: process.env.OAUTH2_CLIENT_SECRET,
}

const tokenStore = {
  refreshToken: '---redacted--'
}

const twitterAPI = new TwitterApi(credentials);
const { client: refreshedClient, accessToken, refreshToken: newRefreshToken } = await twitterAPI.refreshOAuth2Token(tokenStore.refreshToken);

console.log(accessToken, newRefreshToken) // Everything is ok.

and got all my tokens refreshed correctly, no Authorization issue.

Check if your client ID and client secret are correctly defined.

If the problem continues, please enable request debugging and paste request/response content here.

alkihis avatar Jun 30 '22 18:06 alkihis