简体   繁体   English

使用gapi.auth.authorize时访问被拒绝错误

[英]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.

相关问题 检测用户在使用gapi.auth.authorize时是否关闭弹出窗口 - Detect if user closes popup when using gapi.auth.authorize gapi.auth.authorize:TypeError:cv(...)为null - gapi.auth.authorize: TypeError: cv(…) is null 带立即数的gapi.auth.authorize:true不起作用 - gapi.auth.authorize with immediate: true is not working gapi.auth.authorize:TypeError:_.Uu不是函数 - gapi.auth.authorize: TypeError: _.Uu is not a function 在node-webkit应用程序上通过Google登录时,不会调用gapi.auth.authorize回调 - gapi.auth.authorize callback doesn't get called when doing sign-in via Google on node-webkit app 如何将login_hint传递给gapi.auth.authorize? - How do I pass login_hint to gapi.auth.authorize? Google OAuth gapi.auth.authorize X-Frame-Options:SAMEORIGIN - Google OAuth gapi.auth.authorize X-Frame-Options: SAMEORIGIN 对于 javascript 调用 api “gapi.auth.authorize” 的 google 分析没有得到执行。 - For javascript the call to api “gapi.auth.authorize” for google analytics not getting executed. 为什么带有“ immediate:false”的gapi.auth.authorize不关闭弹出窗口并触发回调? - Why gapi.auth.authorize with “immediate: false” doesn't close popup and fire callback? 使用 Firebase 身份验证和 gAPI? - Using Firebase Auth & gAPI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM