【问题标题】:signature_invalid when trying to get request_token (Yahoo)尝试获取 request_token 时签名无效(雅虎)
【发布时间】:2012-08-22 02:04:01
【问题描述】:

我开始开发一个脚本来获取雅虎用户的联系人。在获取联系人之前,当我执行这样的链接请求时,我在获取请求令牌时遇到问题:

<a class="yahoo" href="https://api.login.yahoo.com/oaut/v2/get_request_token?oauth_nonce=<?php echo uniqid() ?>&oauth_timestamp=<?php echo time() ?>&oauth_consumer_key=<?php echo $yahoo_consumer_key ?>&oauth_signature_method=plaintext&oauth_signature=<?php echo $yahoo_consumer_secret ?>&oauth_version=1.0&xoauth_lang_pref=en-us&oauth_callback=<?php echo urlencode('http://myfullurl.com') ?>">Get Contacts</a>

我收到 HTTP 标头 401 Forbidden 并显示消息:oauth_problem=signature_invalid

我不知道我是否正确设置了链接,但这是我通过http://developer.yahoo.com/oauth/guide/oauth-sign-plaintext.html了解的内容

参考:http://developer.yahoo.com/oauth/guide/oauth-requesttoken.html

【问题讨论】:

    标签: php oauth yahoo yahoo-api


    【解决方案1】:

    您对https://api.login.yahoo.com/oaut/v2/get_request_token 的调用必须是服务器端调用,而不是用户必须单击的链接。

    如果您不知道该怎么做,您可能应该使用一些 PHP OAuth library 来为您处理。

    然后,正如雅虎在their documentation 中所说:

    对于 get_request_token 的请求,没有 Token Secret。仅包括 Consumer Secret,后跟“&”字符。

    您的oauth_signature 应该是:

    &oauth_signature=<?php echo $yahoo_consumer_secret . "&" ?>
    

    【讨论】:

    • 不需要是服务器端请求,请在此处阅读 6.1.1 oauth.net/core/1.0/#auth_step1。必须是带有 GET 或 POST 的 HTTP 请求,PHP OAuth 库只需通过 cURL 执行请求,如果我通过用户单击链接执行请求,则该请求是相同的。我认为消费者秘密末尾的“&”只是为了在 GET 的情况下与其他变量分开,但我也尝试过但没有奏效。
    • 不,不一样。文档指出:**The Consumer** obtains an unauthorized Request Token by asking the Service Provider to issue a Token.消费者是您的网络应用程序,不是用户的浏览器! response token 也将被发送回用户的浏览器,而不是您需要的 Web 应用程序。那么您当然也不希望 consumer_secret 在您的 HTML 源代码中向公众提供。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    • 2011-11-12
    • 2015-11-01
    • 2018-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多