Reputation: 4741
I am using google-python-client-api for Blogger API (Service Account - OAuth).
This is my code (which is taken my tasks api example)
import httplib2
import pprint
import sys
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
f = file("privatekey.p12", "rb")
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
"[email protected]",
key,
scope = "https://www.googleapis.com/auth/blogger")
http = httplib2.Http()
http = credentials.authorize(http)
service = build("blogger", "v3", http=http)
when I am running this code, its showing
Message File Name Line Position
Traceback
<module> D:\Code\myScripts\py\gData.py 20
build build\bdist.win32\egg\apiclient\discovery.py 191
new_request build\bdist.win32\egg\oauth2client\client.py 402
_refresh build\bdist.win32\egg\oauth2client\client.py 569
_do_refresh_request build\bdist.win32\egg\oauth2client\client.py 625
AccessTokenRefreshError: invalid_grant
What's the problem and how should I fix it??
I even tried tasks.py
example code.. and its even showing the same error
I am very much sure that service account email address is right
Upvotes: 1
Views: 1025
Reputation: 78
I'm running into a similar problem with querying BigQuery. From what little documentation exists on the interwebs, it appears to be an issue with poor resolution clocks causing timing errors that invalidate the SignedJWTCredentials. One proposed solution is to ensure that your clock's timer is synchronized with ntp. Since I'm deploying to Heroku, my solution is to fail gracefully and then retry.
See also https://code.google.com/p/google-api-php-client/wiki/OAuth2#Solving_invalid_grant_errors
Upvotes: 1