我正在尝试访问一个使用谷歌API的第三方API,但为了做到这一点,我必须使用gapi.auth.authorize来获取我的谷歌信息并传递给他们的API。在发现userinfo/email已被弃用后,我正在使用新的电子邮件范围,但仍然收到access_denied错误。
以下是我遇到问题的简化版本...
index.html
<!doctype html>
<html>
<head>
</head>
<body>
<p>Tripping all day...</p>
<p id="output"></p>
<script src="auth.js"></script>
<script type="text/javascript">
function init() {
console.log('init');
checkAuth();
}
</script>
<script src="https://apis.google.com/js/client.js?onload=init"> </script>
<script>
document.getElementById("output").innerHTML = "Coooooorrrrrraaaaalll";
</script>
`enter code here`</body>
</html>
auth.js
CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com';
var SCOPES = 'email';
function handleAuth(authResult) {
console.log('handle auth');
console.log(authResult);
}
function checkAuth() {
console.log('check auth');
gapi.auth.authorize({client_id: CLIENT_ID, scope: SCOPES, immediate: true, cookie_policy: 'single_host_origin'}, handleAuth);
}
当它失败时,控制台日志会输出此错误对象...
client_id: "xxxxxxxxxxxxx.apps.googleusercontent.com"
cookie_policy: "single_host_origin"
error: "immediate_failed"
error_subtype: "access_denied"
expires_at: "1438103114"
expires_in: "86400"
g_user_cookie_policy: "single_host_origin"
issued_at: "1438016714"
response_type: "token"
scope: "email"
state: ""
非常感谢你的帮助,如果你能指出我做错了什么或者下一步该去哪里寻找信息,我将不胜感激。谢谢!