-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Endpoint "media/metadata/create" fails #67
Comments
It seems like it actually makes a successful request, but it fails to parse the result. Here is some extremely hacky code if anyone needs it. It's bad, but it will not throw const crossFetch = require('cross-fetch')
function customTwitterPostForAltText (twitterClient, body) {
const resource = 'media/metadata/create'
const baseHeaders = {
'Content-Type': 'application/json',
Accept: 'application/json'
}
const { requestData, headers } = twitterClient._makeRequest(
'POST',
resource,
null // don't sign JSON bodies; only parameters
)
const postHeaders = Object.assign({}, baseHeaders, headers)
body = JSON.stringify(body)
return crossFetch(requestData.url, {
method: 'POST',
headers: postHeaders,
body
})
.then(res => {
if (res.status !== 200) throw new Error('[customTwitterPostForAltText] ' + JSON.stringify(res))
})
} |
Hi @NiciusB, sorry for the delay. I'm a bit confused, did you solve this issue with the snippet you posted above? |
I did, but it's not ideal since it's ignoring the result of the request. If the request succeeds we have no access to the response, and if twitter returns an error, the actual error message will be lost. Basically what I wanted to do was to upload an image with a caption.
For reference this is the original file: https://github.com/NiciusB/valentine-cards-bot/blob/master/src/cron/sendTweet.js |
Hey @NiciusB do you mind creating a PR that would fix this for our users? We'd really appreciate it, thanks! |
The endpoint
https://upload.twitter.com/1.1/media/metadata/create.json
fails due to content being sent inapplication/x-www-form-urlencoded
, but it only acceptsapplication/json
I tried adding it to
JSON_ENDPOINTS
but it fails with an invalid json response.Code sample:
Doc page for
media/metadata/create
for reference: https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-metadata-createThe text was updated successfully, but these errors were encountered: