在 Yahoo! 中使用 OAuthAPI 请求 (Python) [英] Using OAuth in Yahoo! API Requests (Python)

查看:67
本文介绍了在 Yahoo! 中使用 OAuthAPI 请求 (Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to integrate an application with a Yahoo! api that requires oauth authentication to access protected data.

我正在使用 python-oauth2 并遵循 Yahoo 的 Oauth 授权流程 文档.我已经能够完成与雅虎协商访问令牌的所有步骤,但似乎无法使用 令牌进行身份验证.

I'm using python-oauth2 and following along with the steps listed in Yahoo's Oauth Authorization Flow document. I've been able to complete all of the steps to negotiate an access token with Yahoo, but do not seem to be able to use the 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""

However, all I'm able to get back is an error message that says "Please provide valid credentials. OAuth oauth_problem="signature_invalid", realm="yahooapis.com""

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

What am I doing wrong here? Everything else worked smoothly up to this point.

推荐答案

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

Well I feel a bit sheepish. So it turns out that Yahoo also throws this exact error when you access an invalid API call. So in my case I was accessing a root API when I had to specify a sub API. Moral of the story: beware that oauth errors might be representative of other issues in your app/code.

这篇关于在 Yahoo! 中使用 OAuthAPI 请求 (Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆