401 ( Unauthorised ) error when using jQuery's $.get and GMail API

房东的猫 提交于 2019-12-02 16:00:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!