1

First some background, Using Service Accounts with GData Spreadsheet API for an app installed via Google Apps Marketplace.

    credentials = SignedJwtAssertionCredentials(
                    SERVICE_ACCOUNT_EMAIL,
                    PRIVATE_KEY,
                    scope = SCOPE,
                    sub = "admin@domain.com")
    auth2token = gauth.OAuth2TokenFromCredentials(credentials)
    client = SpreadsheetsClient()
    auth2token.authorize(client)
    q = SpreadsheetQuery(title= "ItemMaster",title_exact=True,)
    feed = client.get_spreadsheets(query = q)

The problem is that the API calls fail randomly with,

AccessTokenRefreshError: Invalid response 403.
Failed to retrieve access token: You are not authorized to perform this request.

I tried doing a test in which 10 API calls are made one after another with 1 second intervals between them, atleast 4 API calls failed with the above error.

I tried checked the quota on API console and that is not being exceeded, Per user limits on the API are at 100 requests/user/second for the Drive API, and billing is enabled.

PS: This question is different from Getting AccessTokenRefreshError: invalid_grant in Google API fro service account and Google API Python Client - AccessTokenRefreshError which are related to invalid_grant while my issue is specifically related to Random Failures of API calls

EDIT: The problem seems to be related to #210 in google-api-python-client

Community
  • 1
  • 1
Gautam
  • 7,868
  • 12
  • 64
  • 105
  • Is this using a refresh token to get a new access token? .... Anyway, I used the Google DrEdit example to code OAuth2, it worked, although needed to add a call to get the access token from the refresh token, as it expires after one hour. But it all works, never seen this issue. – eddyparkinson Jan 29 '14 at 22:32
  • @eddyparkinson Did you use service accounts and spreadsheet API ? – Gautam Jan 30 '14 at 06:29
  • I use GData style "Spreadsheet API" and normal OAuth2 but have also used an API key. Looks like google have changed things, an "API key", looks different to a "service account". An API key also required an email address, so it looks a bit like your code above. – eddyparkinson Jan 30 '14 at 06:59
  • I think I found the issue, [#210](https://code.google.com/p/google-api-python-client/issues/detail?id=210) on google-api-python-client. We are facing a something very similar – Gautam Jan 30 '14 at 07:02
  • Eventually, I've found the solution to your issue here http://stackoverflow.com/a/26931576/1549523 However, in my case the pattern didn't work with an impersonated user, i.e. the `sub` parameter. – Ani Nov 25 '14 at 11:36

0 Answers0