[英]Access Denied Error when using gapi.auth.authorize
I am trying to access a third party's API that uses Google's APIs, but in order to do that, I have to use gapi.auth.authorize to get my Google info to pass to their API. 我正在尝试访问使用Google API的第三方API,但为了做到这一点,我必须使用gapi.auth.authorize将我的Google信息传递给他们的API。 I'm using the new email scope after finding out that userinfo/email is deprecated, but I am still getting an access_denied error. 在发现不推荐使用userinfo / email之后,我正在使用新的电子邮件范围,但我仍然收到access_denied错误。
Here is the boiled down version of what I am having issues with... 这是我遇到的问题的简化版本......
index.html 的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 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);
}
The console log spits out this error object when it fails... 控制台日志在失败时吐出此错误对象...
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: ""
Any insight on what I am doing wrong or where to look next is appreciated. 任何关于我做错了什么或下一步看什么的见解都值得赞赏。 Thanks! 谢谢!
For anyone else having similar issues, I found that if I change the "immediate" parameter in the gap.auth.authorize call to false, it will pop up a box that lets me select a Google account to use. 对于其他有类似问题的人,我发现如果我将gap.auth.authorize调用中的“立即”参数更改为false,它会弹出一个框,让我选择要使用的Google帐户。 From there, everything runs successfully. 从那里,一切都成功运行。
I'm still not 100% on what is happening behind the scenes, but it's working for now. 我仍然不是百分之百地了解幕后发生的事情,但它现在正在发挥作用。 Eventually, I would like to get the immediate authentication working without having to do the pop-up, but that will probably be another question. 最终,我希望立即进行身份验证而不必进行弹出,但这可能是另一个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.