0
votes

I'm getting invalid_grant error when creating a draft. Scopes I requested:

https://www.googleapis.com/auth/gmail.modify 
https://www.googleapis.com/auth/userinfo.profile 
https://www.googleapis.com/auth/contacts.readonly 
https://www.google.com/m8/feeds/ 
https://mail.google.com/ 
https://www.googleapis.com/auth/gmail.settings.basic 
https://www.googleapis.com/auth/calendar

I use python library to interact with Gmail API ( The main problem is that this sometimes works as expected, sometimes it doesn't work and I don't know why. My code look like the one from example here: https://developers.google.com/gmail/api/v1/reference/users/drafts/create

1

1 Answers

2
votes

Based from this thread, the possible problems that cause invalid_grant errors are if your server's clock is out of sync with NTP and/or you've exceeded the refresh token limit. This page also suggested to make sure that you specify access_type=offline in your request.

Here's a related SO post for a checklist of potential causes for the problems:

  1. Server clock/time is out of sync
  2. Not authorized for offline access
  3. Throttled by Google
  4. Using expired refresh tokens
  5. User has been inactive for 6 months
  6. Use service worker email instead of client ID
  7. Too many access tokens in short time
  8. Client SDK might be outdated
  9. Incorrect/incomplete refresh token
  10. User has actively revoked access to our app
  11. User has reset/recovered their Google password

Hope this helps!