Twitter update with media with request.js

﹥>﹥吖頭↗ 提交于 2019-12-25 03:09:01

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!