[英]Access Denied Error when using gapi.auth.authorize
我正在嘗試訪問使用Google API的第三方API,但為了做到這一點,我必須使用gapi.auth.authorize將我的Google信息傳遞給他們的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: ""
任何關於我做錯了什么或下一步看什么的見解都值得贊賞。 謝謝!
對於其他有類似問題的人,我發現如果我將gap.auth.authorize調用中的“立即”參數更改為false,它會彈出一個框,讓我選擇要使用的Google帳戶。 從那里,一切都成功運行。
我仍然不是百分之百地了解幕后發生的事情,但它現在正在發揮作用。 最終,我希望立即進行身份驗證而不必進行彈出,但這可能是另一個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.