使用jQuery的$ .get和GMail API时出现401(未经授权)错误 [英] 401 ( Unauthorised ) error when using jQuery's $.get and GMail API
问题描述
在我让用户使用javascript使用G + API登录后,我试图运行jQuery的$ .get,但是在浏览器控制台中出现401(未经授权)错误.
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.
这是我请求的网址格式:https://www.googleapis.com/gmail/v1/users/myusername%40gmail.com/messages?key=%7Bmyborwserapikey%7D
Here is the format of the url I am requesting: https://www.googleapis.com/gmail/v1/users/myusername%40gmail.com/messages?key=%7Bmyborwserapikey%7D
我也尝试过https://www.googleapis.com/gmail/v1/users/me/messages?key=%7Bmyborwserapikey%7D
登录后都返回401错误.
both are returning the 401 error after logging in.
推荐答案
对Gmail API的每个请求都需要访问令牌,因此API密钥是不够的.
Each request to the Gmail API requires an access token, so an API key will not be enough.
虽然用户可能已使用G + API登录,但该API本身并未授予您的应用对用户Gmail的授权访问权限.
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.
在此处查看有关访问Gmail API的更多详细信息: https://developers.google.com/gmail/api/overview#auth_and_the_gmail_api
Check here for more details on getting access to the Gmail API: https://developers.google.com/gmail/api/overview#auth_and_the_gmail_api
这篇关于使用jQuery的$ .get和GMail API时出现401(未经授权)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!