用于 Twitter 的 HTTParty,包含参数时无法进行身份验证

HTTParty for Twitter, fails to authenticate when params included

我正在尝试使用来自 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})

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

阅读此处的文档 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",