【问题标题】:Access Denied Error when using gapi.auth.authorize使用 gapi.auth.authorize 时访问被拒绝错误
【发布时间】:2015-10-18 00:16:59
【问题描述】:

我正在尝试访问使用 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: ""

感谢您对我做错了什么或下一步看哪里的任何见解。谢谢!

【问题讨论】:

    标签: javascript google-api google-oauth google-api-js-client


    【解决方案1】:

    对于遇到类似问题的其他人,我发现如果我将 gap.auth.authorize 调用中的“立即”参数更改为 false,它会弹出一个框,让我选择要使用的 Google 帐户。从那里开始,一切顺利。

    我仍然不是 100% 了解幕后发生的事情,但它现在正在发挥作用。最终,我希望无需弹出窗口即可立即进行身份验证,但这可能是另一个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-24
      • 2012-12-21
      • 2010-12-23
      相关资源
      最近更新 更多