【问题标题】:Foursquare OAuth2 401 errorFoursquare OAuth2 401 错误
【发布时间】:2012-02-03 06:09:31
【问题描述】:

使用 PHP 和 curl 生成带有此 url 的访问令牌:

https://foursquare.com/oauth2/access_token?client_id=MY_CLIENT_ID&client_secret=MY_SECRET&grant_type=authorization_code&redirect_uri='.urlencode('MY_REDIRECT_URL').'&code='.$token['oauth_token']

这处理得很好并返回一个令牌。只有当我在foursquare.com 重置消费者密钥和秘密时,此令牌才会更改

将该令牌用于

https://api.foursquare.com/v2/users/search?name=test&oauth_token=RETURNED_TOKEN

总是返回 401 错误。我使用了这些说明https://developer.foursquare.com/overview/auth

【问题讨论】:

  • 你有你的访问令牌,很难弄清楚你得到了未经授权的 401。检查http头也许你会发现其他信息。
  • 请检查此以推断出您的 401 oauth.net/core/1.0a/#http_codes
  • 好的,我刚刚在脚本之外的浏览器中测试了用户/搜索 url,它工作正常。我正在检查我的 php 脚本,很快就会发布错误。

标签: php curl oauth oauth-2.0 foursquare


【解决方案1】:

好的,这就是发生的事情:

在 oauth-php 客户端代码中,OAuthRequestSigner 的 getQueryString 方法在构建请求 url 查询字符串时存在以下条件,以防止添加 OAuth 1.0 签名参数:

 (strncmp($name, 'oauth_', 6) != 0

我有一个配置文件来管理我的 OAuth 参数并添加了

 $param=array(
   ...
   'oauth2'=>true
   ...);

传递给OAuthRequestSigner类并将条件调整为

 ( (strncmp($name, 'oauth_', 6) != 0 || $param['oauth2'] )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-13
    • 2017-07-01
    • 2022-06-29
    • 2011-05-28
    • 2021-10-01
    • 2019-08-09
    • 2013-09-13
    • 1970-01-01
    相关资源
    最近更新 更多