我正在尝试访问使用 Google API 的第三方 API,但为了做到这一点,我必须使用 gapi.auth.authorize 将我的 Google 信息传递给他们的 API。在发现 userinfo/email 已弃用后,我正在使用新的电子邮件范围,但我仍然收到 access_denied 错误。
这是我遇到的问题的简化版本...
索引.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: ""
任何关于我做错了什么或下一步看哪里的见解都值得赞赏。谢谢!