removekebab
removekebab

Reputation: 53

Google Content API for Shopping - Python OAuth invalid_grant

I'm attempting to utilize the google content api for shopping to add/update products in my google merchant account. It appears that I'm having some problems with OAuth.

Thanks in advance for the help!

Example Code

f = file("key.p12", 'rb')
CLIENT_SECRET = f.read()
f.close()
ACCOUNT_ID = 'xxxxxxx'
CLIENT_ID = 'xxxxxxxxx.apps.googleusercontent.com'
SERVICE_ACCOUNT_EMAIL =  '[email protected]'
SCOPE = 'https://www.googleapis.com/auth/structuredcontent'
USER_AGENT = 'content-api-example'

credentials = SignedJwtAssertionCredentials(
    SERVICE_ACCOUNT_EMAIL,
    CLIENT_SECRET,
    scope=SCOPE)

http = httplib2.Http()

http = credentials.authorize(http)

auth_token = gdata.gauth.OAuth2TokenFromCredentials(credentials)

entry = gdata.contentforshopping.data.ProductEntry()
...
shopping_client.InsertProduct(entry)

Output

auth2client.client.AccessTokenRefreshError: invalid_grant

Upvotes: 0

Views: 498

Answers (1)

davidtzau
davidtzau

Reputation: 61

It looks like you are using a Service Account to access the API. Make sure you login to the respective Google Merchant Center account you are trying to access and add the Service account email generated from the Google Developer Console (in your code, this is the value within SERVICE_ACCOUNT_EMAIL") to the "Settings > Users" section and grant this email address "standard" or "administrative" access depending on the scope you are requesting.

This is an often missed step and not called out specifically in Google's documentation.

Hope this helps

Upvotes: 2

Related Questions