【问题标题】:HTTParty for Twitter, fails to authenticate when params includedTwitter 的 HTTParty,在包含参数时无法进行身份验证
【发布时间】:2016-06-25 23:33:00
【问题描述】:

我正在尝试使用 Twitter API 中的 verify_credentials endpoint。我想将include_entities 参数设置为false。我可以使用第一个示例进行身份验证(所以我知道我的 oauth_options 值是正确的),但是如果我尝试设置 include_entities 参数,我会收到此错误 {"code"=>32, "message"=>"Could not authenticate you."}。注意:我无法使用 Twitter gem。

作品:

response = HTTParty.get("https://api.twitter.com/1.1/account/verify_credentials.json", headers: {"Authorization" => oauth_options})

不起作用:

response = HTTParty.get("https://api.twitter.com/1.1/account/verify_credentials.json", headers: {"Authorization" => oauth_options}, query: {include_entities: false})

也不起作用

response = HTTParty.get("https://api.twitter.com/1.1/account/verify_credentials.json?include_entities=false", headers: {"Authorization" => oauth_options})

【问题讨论】:

  • 因此包含此查询参数将更改计算的授权值,因为它们包含在签名过程中。你是怎么产生的?
  • 我没有意识到这一点。我认为这就是问题所在。
  • P.S.,如果你想把这个作为答案,我会把它标记为正确的。

标签: ruby-on-rails twitter httparty


【解决方案1】:

确保调整计算授权令牌的逻辑,因为它需要考虑查询参数。

阅读此处的文档https://dev.twitter.com/oauth/overview/authorizing-requests 或使用自动处理它的库。

如果您正确签署请求,我可以确认它有效

$ oksocial 'https://api.twitter.com/1.1/account/verify_credentials.json?include_entities=false' | jq .
{
  "id": 111,
  "id_str": "111",
  "name": "Fred Blogs",

【讨论】:

  • 我该怎么做?
猜你喜欢
  • 2011-08-04
  • 1970-01-01
  • 1970-01-01
  • 2013-02-15
  • 2021-04-14
  • 1970-01-01
  • 2011-04-30
  • 2022-01-01
  • 2023-03-15
相关资源
最近更新 更多