简体   繁体   中英

Trying to update Twitter status with request.js

This returns a "Bad Authentication Data" error

  request.post({
    url: "https://api.twitter.com/1.1/statuses/update.json",
    oauth: {
      consumer_key: auth.twitter.consumerKey,
      consumer_secret: auth.twitter.consumerSecret,
      access_token_key: this.authToken,
      access_token_secret: this.authSecret
    },
    params: {
      status: "Check this out!!"
    }
  }, function(err, response, body) {
    return console.log(err, body); // null '{"errors":[{"message":"Bad Authentication data","code":215}]}'
  });

Any idea what I'm doing wrong?

There are a couple of things that are preventing this from running:

access_token_key should be token , and access_token_secret should be token_secret

Sending POST data works a bit differently with the request module. Try something like this

var r = request.post({url:url, oauth:params}, function(err, resp, body) {
    res.end("Tweet sent successfully");
});

var form = r.form();
form.append("status", "Check this out!!");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM