N8n 0.236.0 Upload Twitter Image via HTTP Node using Twitter OAuth2 fails

I’ve updated to 0.236.0 of n8n and have added my credentials to Twitter OAuth2 API.

I’ve updated my callback URL in the Twitter Developer Portal to https://n8n.mydomain.com/rest/oauth2-credential/callback

I cannot upload an image to Twitter via the HTTP Request to node (using these instructions, to https://upload.twitter.com/1.1/media/upload.json) using the Twitter OAuth2 API credentials. It returns the error:


{
"status":
"rejected",
"reason":
{
"message":
"Forbidden - perhaps check your credentials?",
"timestamp":
1689100303571,
"name":
"NodeApiError",
"description":
"403 - """,
"context":
{
},
"cause":
{
"message":
"403 - """,
"name":
"Error",
"stack":
"Error: 403 - "" at createError (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/createError.js:16:15) at settle (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/settle.js:17:12) at RedirectableRequest.handleResponse (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/adapters/http.js:238:9) at RedirectableRequest.emit (node:events:525:35) at RedirectableRequest.emit (node:domain:489:12) at RedirectableRequest._processResponse (/usr/local/lib/node_modules/n8n/node_modules/follow-redirects/index.js:356:10) at ClientRequest.RedirectableRequest._onNativeResponse (/usr/local/lib/node_modules/n8n/node_modules/follow-redirects/index.js:62:10) at Object.onceWrapper (node:events:628:26) at ClientRequest.emit (node:events:525:35) at ClientRequest.emit (node:domain:489:12) at HTTPParser.parserOnIncomingClient (node:_http_client:693:27) at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17) at TLSSocket.socketOnData (node:_http_client:534:22) at TLSSocket.emit (node:events:513:28) at TLSSocket.emit (node:domain:489:12) at addChunk (node:internal/streams/readable:315:12) at readableAddChunk (node:internal/streams/readable:289:9) at TLSSocket.Readable.push (node:internal/streams/readable:228:10) at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)"
}
}
}

I tried creating a set of credentials within n8n the Twitter OAuthAPI (not OAuth2) but am unable to confirm the connection within the “Credentials” screen, it returns an error as follows, presumably because the callback URL for OAuth is https://n8n.mydomain.com/rest/oauth1-credential/callback and not https://n8n.mydomain.com/rest/oauth2-credential/callback (which is the callback in my Twitter Developer console, per the above).

OAuth Authorization Error
There was a problem generating the authorization URL
Request failed with status code 401

So it appears to me that you cannot upload an image using the HTTP request node via the Twitter1.1 API with the Twitter OAuth2 credentials in n8n. As we know, there is not a Twitter API v2 method to upload images, which is why we use the 1.1 API.

I also checked the new Twitter node, and I see that we can attach a media ID to a tweet, but we get that media ID after we upload the image using the HTTP Request node to Twitter via the 1.1 API. Since the upload is failing, I’m not able to get a media ID to attach to the tweet.

Is there something else I need to do to or change to upload images, given the new Twitter OAuth2 credentials?

Hi @mmac, as for posting images, this workflow would do the job for me a while back:

A fellow forum user got it to work like so more recently:

Perhaps you can give these a go using the new OAuth2 credentials from [email protected]?

The examples you linked is how I’ve been uploading images already. It isn’t working anymore, that’s the problem.

Thanks for clarifying @mmac. I could actually reproduce the problem just now and am only getting 403s with no further error details from Twitter when using v1.1 endpoints. This is for both OAuth1 and OAuth2 and is not even limited to image uploads. v2 endpoints seem to work, but everything on v1.1 fails now despite having worked in the past.

I reckon it’s because I don’t pay for anything and only get very basic access to everything Twitter. Perhaps @Jon as a Twitter Blue user can give this a go when he has a few minutes?

Ah I am no longer a Twitter blue user, I am all about Threads now :smiley:

The Twitter API v1.1 endpoint https://upload.twitter.com/1.1/media/upload.json is still available under the free API access tier, because there is no V2 endpoint for media uploads.

So the problem is that, assuming you have 1 app within your Twitter Developer Console (you need to pay for more apps, even if you are only accessing free endpoints like posting a tweet or uploading media), to post tweets you need to use OAuth2 and API v2 and to upload media to the v1.1 API you need to use OAuth, not OAuth2.

Within n8n, to authenticate your n8n app with Twitter, you need to provide a callback URL. The callback URL within n8n is different for OAuth and Oauth2. But, since you only have 1 app within the Twitter Developer Console you cannot provide both n8n Callback URLs to the Callback URL field in the Developer Console.

To work around this, this morning I have created a second Twitter account, a second Twitter developer account.

My main account is set up in n8n with OAuth2 and can access Twitter API v2 endpoints, using callback URL https://n8n.mydomain.com/rest/oauth2-credential/callback to authenticate. You use the Client ID and Client Secret from Twitter within n8n’s credentials screen.

The second, new account is set up in n8n with OAuth and can access Twitter API v1.1 endpoints, using callback URL https://n8n.mydomain.com/rest/oauth1-credential/callback to authenticate. You use the API Key and API Key Secret from Twitter within n8n’s credentials screen.

So the way that n8n is using different callback URLs for Oauth and Oauth2 is creating a need for 2 separate apps within the Twitter Developer console, which requires one to pay for Twitter API access or to create dummy developer accounts for access to a second app.

Hey @mmac,

I have 2 different callback urls set for one twitter app one using oauth1 and one using oauth2, I am not sure if this is because I have an older app but for me both the v1 and v2 API works.

Did you try adding the second callback url under the app info?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.