question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OAuth 2 error for POST /2/tweets FIXED

See original GitHub issue

I am using the latest version of twitter-lite

I thought we were using oAuth 1.0a, but I get this error:

{
  _headers: Headers {
    [Symbol(map)]: [Object: null prototype] {
      'set-cookie': [Array],
      'content-type': [Array],
      'cache-control': [Array],
      'content-length': [Array],
      'x-response-time': [Array],
      'x-connection-hash': [Array],
      date: [Array],
      server: [Array],
      connection: [Array]
    }
  },
  title: 'Unsupported Authentication',
  detail: 'Authenticating with OAuth 2.0 Application-Only is forbidden for this endpoint.  Supported authentication types are [OAuth 1.0a User Context, OAuth 2.0 User Context].',
  type: 'https://api.twitter.com/2/problems/unsupported-authentication',
  status: 403
}

Here is the code

async function createNewTwitterClient (subdomain, extension, response, twitterAppConfig, version) {
  const twitter = require("twitter-lite");
  return new twitter({
    subdomain,
    consumer_key: twitterAppConfig.consumerKey, // from Twitter.
    consumer_secret: twitterAppConfig.consumerSecret,
    extension, // true is the default (this must be set to false for v2 endpoints),
    access_token_key: twitterAppConfig.accessTokenKey, // from your User (oauth_token)
    access_token_secret: twitterAppConfig.accessTokenSecret, // from your User (oauth_token_secret)
    bearer_token: response ? response?.access_token : null,
    version
  });
}

const apiClient = await createNewTwitterClient('api', false, null, twitterAppConfig,'2');
const apiResponse = await apiClient.getBearerToken();
const twitterApiClient = await createNewTwitterClient('api', false, apiResponse, twitterAppConfig,'2');

twitterApiClient.post('tweets', { text: 'hello world' }).then(tweet => {
	// do something
}).catch();

In Postman, it works fine:

image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:15

github_iconTop GitHub Comments

3reactions
charlesr1971commented, Sep 19, 2022

All I know is that the current Twitter-lite V2 /tweets endpoint does NOT work.

My PR code updates, work with me.

I must say your content type error message, is a little strange.

1reaction
charlesr1971commented, Feb 28, 2022

God, this MarkDown Editor is terrible. You would think GitHub could sort this out? 😩

Read more comments on GitHub >

github_iconTop Results From Across the Web

403 error when trying to POST to /2/tweets using example in ...
I'm following the example curl command at POST /2/tweets | Docs | Twitter ... Supported authentication types are [OAuth 1.0a User Context, OAuth...
Read more >
OAuth 2 Request Example · Issue #149 · g8rswimmer/go-twitter
Hi, I was trying to post a tweet. It seems like I would need to make use of the OAuth 2 authorization flow....
Read more >
'Unsupported Authentication', detail ... - Stack Overflow
The error message. Authenticating with OAuth 2.0 Application-Only. Indicates that the bearer token sent in the API request represents the ...
Read more >
OAuth 2.0 App-Only (Bearer Token) | Docs - Twitter Developer
App only authentication and OAuth 2.0 Bearer Token ... An application makes a request to the POST oauth2/token endpoint to exchange ... Common...
Read more >
OAuth2 and Twitter API - Questions - n8n community
Describe the issue/error/question Hello, First of all, to present you the context: I need to use the API v2 of twitter But I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found