Twitter api returns unsupported authentication; "detail": "Authenticating with Unknown is forbidden for this endpoint."

Viewed 117

I am trying to send a https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-id api to obtain some user info, but the response is always

{
  statusCode: 403,
  data: '{\n' +
    '  "title": "Unsupported Authentication",\n' +
    '  "detail": "Authenticating with Unknown is forbidden for this endpoint.  Supported authentication types are [OAuth 1.0a User Context, OAuth 2.0 Application-Only, OAuth 2.0 User Context].",\n' +
    '  "type": "https://api.twitter.com/2/problems/unsupported-authentication",\n' +
    '  "status": 403\n' +
    '}'
}

Even though I have successfully have the oauth_access_token and oauth_access_secret as described in https://developer.twitter.com/en/docs/authentication/oauth-1-0a/obtaining-user-access-tokens Below is my code snippet to send the request;

// server.js
app.get('/api/twitter/temp/profile', async (req, res) =>{
  const { oauth_access_token, oauth_access_token_secret } = access_tokens[tmp_token]; 
  try {
    // const ids = req.query.ids.join()
    const ids = req.query.ids
    console.log("ids "+ids)
    console.log(oauth_access_token, oauth_access_token_secret)
    const response = await oauth.sendRequest({
      method: 'get',
      url: `https://api.twitter.com/2/users?ids=${ids}`,
      oauth_access_token,
      oauth_access_token_secret
    })
    console,log(response)
    res.json({message: 'ok'})
  } catch (error) {
    console.log(error)
  }
})

The library that I used to send the request to twitter (taking care of headers etc) is https://github.com/ciaranj/node-oauth/blob/a7f8a1e21c362eb4ed2039431fb9ac2ae749f26a/lib/oauth.js#L486, so the oauth in my server.js is a wrapper of that library etc.

0 Answers
Related