【问题标题】:Using OAuth in Yahoo! API Requests (Python)在 Yahoo! 中使用 OAuth API 请求 (Python)
【发布时间】:2011-11-20 23:05:48
【问题描述】:

我正在尝试将应用程序与 Yahoo! 集成。需要 oauth 身份验证才能访问受保护数据的 API。

我正在使用 python-oauth2 并按照 Yahoo 的 Oauth Authorization Flow 文档中列出的步骤进行操作。我已经能够完成与 Yahoo 协商访问令牌的所有步骤,但似乎无法使用 token to authenticate

这是我的代码:

import oauth2 as oauth

def list_users(token):
    # token is the access token i save in the DB
    oauth_token = oauth.Token(token.token, token.secret)
    consumer = oauth.Consumer(key=settings.OATH_CONSUMER_KEY, 
                              secret=settings.OATH_SECRET)
    client = oauth.Client(consumer, oauth_token)
    resp, content = client.request((LIST_USERS_URL), "GET")
    return content

但是,我能得到的只是一条错误消息,上面写着“请提供有效的凭据。OAuth oauth_problem="signature_invalid", realm="yahooapis.com"”

我在这里做错了什么?到目前为止,其他一切都很顺利。

【问题讨论】:

  • 在调用https://api.login.yahoo.com/oauth/v2/request_auth? 并最终前往https://api.login.yahoo.com/oauth/v2/get_token 获取实际的access_token 之前,您是否运行过https://api.login.yahoo.com/oauth/v2/get_request_token 过程?一个常见问题是将 request_token 与 access_token 混淆。
  • 是的,我正在获取请求令牌和访问令牌,并使用访问令牌进行身份验证。
  • 如果access_token没问题,唯一的小错误是resp, content = client.request(LIST_USERS_URL), "GET")中缺少“(”。最后要检查的是application scopes,注册时是否正确?

标签: python oauth yahoo-api


【解决方案1】:

嗯,我觉得有点害羞。所以事实证明,当您访问无效的 API 调用时,雅虎也会抛出这个确切的错误。因此,就我而言,当我必须指定子 API 时,我正在访问根 API。故事的寓意:注意 oauth 错误可能代表您的应用/代码中的其他问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-29
    • 2014-10-10
    • 2014-08-08
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    • 2021-08-31
    相关资源
    最近更新 更多