I'm developing a contact importer from Yahoo! and GMail to a web app we're doing, using Python and DJango, and I'm facing the following issue with Yahoo!.
I'm able to request my authorization token and my oauth verifier, but, when I'm going to exchange it for an access token so I can make signed calls to Yahoo's API, I get the following response:
'oauth_problem=timestamp_refused&oauth_acceptable_timestamps=1338401179-1338402379'
and, here's the timestamp I generated:
oauth_timestamp=1338401803
As you can see, my timestamp is in the acceptable timestamp range the're asking.
Here's the function I wrote generate the api call to get my access token:
def _yahoo_access_url(request, token, verifier):
plain_url = settings.YAHOO_GET_ACCESS_URL
signature = '&'.join((settings.YAHOO_SECRET + '%26', request.session['oauth_data']['oauth_token_secret']))
nonce_charset = string.ascii_lowercase + string.ascii_uppercase + string.digits
nonce = ''.join(random.sample(nonce_charset, 6))
parameters = {
'oauth_consumer_key': settings.YAHOO_KEY,
'oauth_signature_method': 'PLAINTEXT',
'oauth_version': '1.0',
'oauth_verifier': verifier,
'oauth_token': token,
'oauth_timestamp': int(time.time()),
'oauth_nonce': nonce,
'oauth_signature': signature,
}
return settings.YAHOO_GET_ACCESS_URL % urllib.urlencode(parameters)
Then, I was doing some research to solve my problem and at the LinkedIn developers forum, I found someone with the same problem I had, the answer they gave him was that his server time was wrong and it was generating bad timestamps, I found a Yahoo! web service to get timestamps, so, I modified my function this way:
def _yahoo_access_url(request, token, verifier):
plain_url = settings.YAHOO_GET_ACCESS_URL
signature = '&'.join((settings.YAHOO_SECRET + '%26', request.session['oauth_data']['oauth_token_secret']))
nonce_charset = string.ascii_lowercase + string.ascii_uppercase + string.digits
nonce = ''.join(random.sample(nonce_charset, 6))
timestamp = eval(urllib2.urlopen(settings.YAHOO_GET_TIME_URL, 'GET').read())
parameters = {
'oauth_consumer_key': settings.YAHOO_KEY,
'oauth_signature_method': 'PLAINTEXT',
'oauth_version': '1.0',
'oauth_verifier': verifier,
'oauth_token': token,
'oauth_timestamp': timestamp['Result']['Timestamp'],
'oauth_nonce': nonce,
'oauth_signature': signature,
}
return settings.YAHOO_GET_ACCESS_URL % urllib.urlencode(parameters)
This way, I get a timestamp directly from the Yahoo!'s Servers but, I'm still getting the same problem:
Response: 'oauth_problem=timestamp_refused&oauth_acceptable_timestamps=1338401958-1338403158'
Timestamp: oauth_timestamp=1338402557
It still in range.
What am I doing wrong? am I missing something?, any clue or advice will be very very welcome,
Thank you in advance
I had this problem and I fixed it only set my timestamp with the server. Ex: I'm from Brazil and my server is EUA, I had to reduce 2 hours on my timestamp = -7200. So it works very well, I think that this is a little bug, because others APIs don't have the same error.