0
votes

I have an application that uses OAuth 2 to access Gmail. This is working fine for most users. For some users, however, my application fails at the point of trying to read the Gmail labels, with http error 403 (forbidden). Keep in mind that previous to this API call, I have accessed the user profile successfully. Here is the call that fails:

GET /gmail/v1/users/[email protected]/labels?access_token=ya29.fwI_zL1rF3xOIQcHNzpBhmjVlJhRpofkh4a9mVvwhYRo6H09qX5RNKv76zKT7e6-sEZr

I am requesting the following scopes when getting the access token, and the user has logged in to Google and accepted the request for access (and I can see this when we look at his security dashboard):

https://www.googleapis.com/auth/calendar
https://www.googleapis.com/auth/userinfo.profile
https://www.google.com/m8/feeds
https://www.googleapis.com/auth/tasks
https://www.googleapis.com/auth/gmail.labels
https://mail.google.com/

Note that I just added the gmail.labels scope in at attempt to fix this. Again, this code is working fine for most users - why do some users fail the label request?

1
Are you aware of that a Google access token has a lifespan of one hour before it becomes invalid? - Tholle
Yes I am quite aware of that. I am making the label access call within milliseconds of obtaining the token (via a refresh token). - Jeff McKay
Great :) Maybe some tokens contain characters not allowed in a URL parameter? Maybe you have to URL encode it first. - Tholle
Also, you can try the shorthand me instead of [email protected] which will work in every case. - Tholle
What is the error detail (it's in the HTTP body)? - Eric D

1 Answers

0
votes

Use the shorthand value me instead of [email protected] and the user who the access token belongs to will be used automatically.