问题
I'm trying to run jQuery's $.get after having a user log in with the G+ API with javascript, but am getting a 401 ( unauthorised ) error in the browser console.
Here is the format of the url I am requesting: https://www.googleapis.com/gmail/v1/users/myusername%40gmail.com/messages?key=%7Bmyborwserapikey%7D
I've also tried https://www.googleapis.com/gmail/v1/users/me/messages?key=%7Bmyborwserapikey%7D
both are returning the 401 error after logging in.
回答1:
Each request to the Gmail API requires an access token, so an API key will not be enough.
While the user may have logged in with the G+ API that does not by itself give your app authorized access to the user's Gmail.
Check here for more details on getting access to the Gmail API: https://developers.google.com/gmail/api/overview#auth_and_the_gmail_api
来源:https://stackoverflow.com/questions/25334746/401-unauthorised-error-when-using-jquerys-get-and-gmail-api