【问题标题】:Twitter Oauth2 - Error in obtaining the bearer tokenTwitter Oauth2 - 获取不记名令牌时出错
【发布时间】:2015-02-22 06:15:51
【问题描述】:

我已按照并仔细检查了从 https://dev.twitter.com/oauth/application-only 获取不记名令牌的步骤

我不断收到以下错误:
状态:403禁止 {"errors":[{"code":99,"message":"无法验证您的凭据","label":"authenticity_token_error"}]}

我尝试在正文和查询参数中传递 grant_type=client_credentials。

我点击的网址是:https://api.twitter.com/oauth2/token?grant_type=client_credentials

标题集: 授权:基本 [base64encoded(client_key:client_secret)] 内容类型:application/x-www-form-urlencoded;charset=UTF-8

我正在使用海报作为其余客户端来拨打电话。

谁能指出我可能出错的地方。

非常感谢。

【问题讨论】:

  • 使用命令行 curl 似乎对我有用;您可以通过以下方式验证您是否拥有正确的消费者密钥和秘密:curl -u <consumer_key>:<consumer_secret> -X POST -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" https://api.twitter.com/oauth2/token?grant_type=client_credentials,这应该会给您一个访问令牌

标签: rest twitter oauth oauth-2.0


【解决方案1】:

发送“grant_type=client_credentials”作为负载。

var options = {
    "method":"post",
    "headers": { 
      "Authorization":"Basic " + Utilities.base64Encode(param),
      "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"
    },
    "payload" : "grant_type=client_credentials"
  };

  var response = UrlFetchApp.fetch(TOKEN_URL,options);

【讨论】:

    猜你喜欢
    • 2018-11-03
    • 2021-04-06
    • 2020-06-20
    • 2012-07-14
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多