在Yahoo! API请求中使用OAuth(Python)
我正在尝试将一个应用程序与Yahoo的API集成,这个API需要用到oauth认证才能访问受保护的数据。
我使用的是python-oauth2,并且按照Yahoo的Oauth授权流程文档中的步骤进行操作。我已经完成了与Yahoo协商访问令牌的所有步骤,但似乎无法使用这个令牌进行认证。
这是我的代码:
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”
我在这里做错了什么呢?到目前为止,其他的步骤都很顺利。
1 个回答
0
我有点不好意思。原来,当你访问一个无效的API调用时,Yahoo也会出现这个错误。所以在我的情况下,我本来应该访问一个子API,却错误地访问了根API。这个故事告诉我们:要注意,oauth错误可能代表你应用程序或代码中的其他问题。