【问题标题】:Twitter API, "Unable to verify your credentials."Twitter API,“无法验证您的凭据。”
【发布时间】:2016-10-15 10:34:46
【问题描述】:

正是它在锡上写的。

无论如何,这段代码应该可以工作。它完全遵循https://dev.twitter.com/oauth/application-only 页面所说的内容。然而,它不断返回{{"errors":[{"code":99,"message":"Unable to verify your credentials","label":"authenticity_token_error"}]} [Finished in 0.551s],我不知道为什么。

var request = require('request');

var options = {
  url: 'https://api.twitter.com/oauth2/token',
  method: 'POST',
  headers: {
    "Authorization": "Basic " + new Buffer("[key]:[secretkey]").toString('base64'),
    "Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"
  },
  body: "grant_type=client_credentials"
};

request.post(options, function(error, response, body){
  console.log(body);
});

作为一个简短的说明,这里的代码中省略了密钥和密钥,因为它存在固有的敏感性。您可以将自己的密钥/密钥放在那里尝试,但我不愿意提供自己的。

谢谢!

编辑:

问题最初是 contentType 应该是 Content-Type,并且在技术上修复了它,但实际上它只是改变了我得到的错误。

更新:

将缓冲区密钥转码为 base64 并返回表明授权密钥的完整性在整个编码过程中保持不变,并且根据 Twitter 提供的文档,Basic [base64keyhash] 是有效的。

【问题讨论】:

  • 文档列表“如果尝试过于频繁,请求将被拒绝,并使用代码 99 的 HTTP 403。”也许尝试与新客户合作,直到您成功为止

标签: node.js twitter twitter-oauth


【解决方案1】:

由于您已经在选项中指定方法:“POST”,请尝试使用 request() 而不是 request.post():

var request = require('request');

var options = {
  url: 'https://api.twitter.com/oauth2/token',
  method: 'POST',
  headers: {
    "Authorization": "Basic " + new Buffer("[key]:[secretkey]").toString('base64'),
    "contentType":"application/x-www-form-urlencoded;charset=UTF-8"
  },
  body: "grant_type=client_credentials"
};

request(options, function(error, response, body){
  if(error) {
    console.log(error);
  } else {
    console.log(response.statusCode, body);
  }
});

【讨论】:

    猜你喜欢
    • 2015-10-11
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 2013-11-28
    • 2021-03-08
    • 2020-07-18
    • 2015-06-02
    • 2021-04-14
    相关资源
    最近更新 更多