node-twitter
node-twitter copied to clipboard
Not possible to add metadata to medias
I'm trying to add metadata to an uploaded media but I get the following error :
{
"request": "/1.1/media/metadata/create.json",
"error": "Invalid json payload."
}
Here is the Twitter doc : https://dev.twitter.com/rest/reference/post/media/metadata/create.html
My guess is that the request header and/or body needs to be changed in this case.
I get a 400 error when I try to add metadata. Here's what my request and error look like:
data = await readFile();
media = await client.post("media/upload", { media: data });
alt_text = "foobar";
client.post("media/metadata/create", {
media_id: media.media_id_string,
alt_text: {
text: alt_text
},
});
400 error response
Error: HTTP Error: 400 Bad Request
at Request._callback (/home/my-repo/node_modules/twitter/lib/twitter.js:180:25)
at Request.self.callback (/home/my-repo/node_modules/request/request.js:185:22)
at Request.emit (node:events:390:28)
at Request.emit (node:domain:475:12)
at Request.<anonymous> (/home/my-repo/node_modules/request/request.js:1154:10)
at Request.emit (node:events:390:28)
at Request.emit (node:domain:475:12)
at IncomingMessage.<anonymous> (/home/my-repo/node_modules/request/request.js:1076:12)
at Object.onceWrapper (node:events:509:28)
at IncomingMessage.emit (node:events:402:35)
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^
Error: HTTP Error: 400 Bad Request
at Request._callback (/home/my-repo/node_modules/twitter/lib/twitter.js:180:25)
at Request.self.callback (/home/my-repo/node_modules/request/request.js:185:22)
at Request.emit (node:events:390:28)
at Request.emit (node:domain:475:12)
at Request.<anonymous> (/home/my-repo/node_modules/request/request.js:1154:10)
at Request.emit (node:events:390:28)
at Request.emit (node:domain:475:12)
at IncomingMessage.<anonymous> (/home/my-repo/node_modules/request/request.js:1076:12)
at Object.onceWrapper (node:events:509:28)
at IncomingMessage.emit (node:events:402:35)
I tried the adjustment mentioned earlier and it didn't work for me. All of the reference links are dead now, so here's the current one: https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-metadata-create
Alright well I moved on to twitter-lite and it works: https://github.com/draftbit/twitter-lite/blob/master/test/twitter.test.js#L219
Glad I saw this post https://github.com/desmondmorris/node-twitter/issues/333