问题
I am trying to post a update_with_media on twitter with node.js and request.js. I would like to post the image base64 encode:
var request = require('request');
var r = request.post({
url: "https://api.twitter.com/1.1/statuses/update_with_media.json",
oauth: {
consumer_key: '...',
consumer_secret: '...',
token: '...',
token_secret: '...'
}
}, function(err, response, body) {
return console.log(err, body);
});
var form = r.form();
form.append("status", "Test...");
form.append("media[]", "...");
Unfortunately I get an Error: '{"errors":[{"code":189,"message":"Error creating status."}]}' Before I tried to post a normal update without an image. This worked fine.
What am I doing wrong?
回答1:
Having a look at adaline / twitter_update_with_media.coffee helped: The working solution looks like:
var buffer = new Buffer(imageData, 'base64');
var r = request.post({
url: "https://api.twitter.com/1.1/statuses/update_with_media.json",
oauth: {
consumer_key: '...',
consumer_secret: '...',
token: '...',
token_secret: '...'
}
}, function(err, response, body) {
return console.log(err, body);
});
var form = r.form();
form.append('status', "TEST...");
form.append('media[]', buffer);
来源:https://stackoverflow.com/questions/20830837/twitter-update-with-media-with-request-js