I'm trying to integrate an application with a Yahoo! api that requires oauth authentication to access protected data.
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.
Here is my code:
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
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.
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.
来源:https://stackoverflow.com/questions/8205534/using-oauth-in-yahoo-api-requests-python