Chrome上的Google Auth API Javascript idpiframe初始化错误 [英] Google Auth API Javascript idpiframe initialization error on Chrome

查看:806
本文介绍了Chrome上的Google Auth API Javascript idpiframe初始化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GSuite,我正在编写一个非常简单的网络应用程序来使用Google Auth API,我得到一个例外idpiframe_initialization_failed。



现在我有了谷歌示例中显示的确切HTML:


I use GSuite and I'm coding a very simple web app to use Google Auth API, and I get an exception "idpiframe_initialization_failed".

Now I have the exact HTML as shown in the google Sample: https://developers.google.com/api-client-library/javascript/samples/samples

1) I've created a project on the Google Developer Console

2) I setup the OAUTH authorization screen

3) I've created the client ID, creating restrictions and redirection URL

4) I've also created the API KEY

5) Finally I've enabled the People API, because discovery services was failing when setting the discoveryDocs parameter

With all of these steps, When I call the gapi.client.init, it raises an exception ONLY in chrome, I cannot understand why.

The code for initializing the API is:

    gapi.client.init({
        apiKey: 'MY_API_KEY',
        discoveryDocs: ["https://people.googleapis.com/$discovery/rest?version=v1"],
        clientId: 'MY_CLIENT_ID.apps.googleusercontent.com',
        scope: 'profile'
    }).then(function (response) {
      // Listen for sign-in state changes.
      gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);

      // Handle the initial sign-in state.
      updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
    },function(reason){
        console.log('onerror');
        console.log(reason);
      // Listen for sign-in state changes.
      gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);

      // Handle the initial sign-in state.
      updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());

The code is running the error block, and the message is:

details: "Failed to read the 'localStorage' property from 'Window': Access is denied for this document."
error:"idpiframe_initialization_failed"

Any ideas why I'm coming into this error?

Thanks!

解决方案

I encountered the same issue. After investing some time, found the reason. This error is because in chrome settings, you have the Block third-party cookies and site data option enabled.

It can be resolved by disabling this option: "To find the setting, open Chrome settings, type "Content settings" in the search box, click the Content Settings button, and view the fourth item under Cookies." Uncheck the box "Block third-party cookies and site data".

Hopefully this helps you in resolving your issue.

这篇关于Chrome上的Google Auth API Javascript idpiframe初始化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆