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

All my requests to v2 are forbidden.

Open wholelott4 opened this issue 4 years ago • 1 comments

So, the authentication works well and the requests are going with the bearer token correctly, but always return Forbidden.

[GET api.twitter.com/2/users/me] { method: 'GET', headers: { 'x-user-agent': 'Node.twitter-api-v2', Authorization: 'Bearer TlpSeTBIVXZGVjNocnBNeE5uancwek9VSFB0ZlFXbG4zWGpEQ09XX2JTN1BaOjE2NTA1MjEzMDkyNDg6MTowOmF0OjE', 'accept-encoding': 'br;q=1.0, gzip;q=0.8, deflate;q=0.5, *;q=0.1' }, timeout: undefined, agent: undefined } Request failed with code 403, data: { title: 'Forbidden', type: 'about:blank', status: 403, detail: 'Forbidden' } Response headers: { 'content-type': 'application/problem+json', 'cache-control': 'no-cache, no-store, max-age=0', 'content-length': '93', 'x-response-time': '133', 'x-connection-hash': 'cfde4998c10139bc8b15be3307b6e00671e235355855774bc754ea8156a2ec7e', date: 'Thu, 21 Apr 2022 06:08:29 GMT', server: 'tsa_d', connection: 'close' }

I have the correct scope: users.read and follows.read, im using oauth2 of course.

I have essential access and this is an app from a project on twitter developer dashboard, im using the oauth2 client id and secret to initialize the twitterAPI for the authentication and then, im using the accesstoken to make the request.

sample code: const client = new twitter.TwitterApi({clientId: 'xyz', clientSecret: 'abc'}); client.loginWithOAuth2({code, codeVerifier, redirectUri: 'http://localhost:4001/api/v1/auth/twitter/callback'}) .then(async ({client: loggedClient, accessToken, refreshToken, expiresIn}) => { const { data } = await loggedClient.v2.me(); return res.status(200).send({data}); })

wholelott4 avatar Apr 21 '22 06:04 wholelott4

Fixed this by adding tweet.read scope, i dont know why it is required but it solved my issue.

wholelott4 avatar Apr 21 '22 06:04 wholelott4