如何解决"idpiframe_initialization_failed"问题?对于本地主机? [英] How to solve "idpiframe_initialization_failed" for localhost?

查看:839
本文介绍了如何解决"idpiframe_initialization_failed"问题?对于本地主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的初始化代码:

            function HandleGoogleApiLibrary() {
                // Load "client" & "auth2" libraries
                gapi.load('client:auth2', {
                    callback: function () {
                        // Initialize client & auth libraries
                        gapi.client.init({
                            apiKey: 'My API Key',
                            clientId: 'My Client ID',
                            scope: 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.me'
                        }).then(
                            function (success) {
                                console.log("Yaaay");
                            },
                            function (error) {
                                console.log("Nope");
                                console.log(error);
                            }
                        );
                    },
                    onerror: function () {
                        // Failed to load libraries
                    }
                });
            }

哪个给我以下错误消息:

Which gives me the following error message:

details: "Not a valid origin for the client: http://127.0.0.1 has not been whitelisted for client ID 388774754090-o7o913o81ldb2jcfu939cfu36kh9h0q6.apps.googleusercontent.com. Please go to https://console.developers.google.com/ and whitelist this origin for your project's client ID."
error: "idpiframe_initialization_failed"

我的应用程序尚未投入生产,因此为了开发,我使用了localhost.事情是,在每个堆栈溢出/引用上,我发现他们已经指定在Authorised JavaScript originsAuthorised redirect URIs上,我必须使用http://localhost而不是http://127.0.0.1.如果执行此操作,则会显示该错误,如果尝试登录,则会显示Permission denied to generate login hint for target domain..

My app is not in production yet, so for development I'm using localhost. Thing is, on every stack overflow / reference I've found they've specified that on Authorised JavaScript origins and Authorised redirect URIs I must use http://localhost instead of http://127.0.0.1. If I do this, I get that error and a Permission denied to generate login hint for target domain. if I try to login.

如果我在两者上都使用http://127.0.0.1,则在初始化时不会获得idpiframe_initialization_failed,但是在尝试登录时却获得了相同的权限被拒绝.

If I use http://127.0.0.1 on both, I get no idpiframe_initialization_failed on initialization, but get the same permission denied when I try to login.

这没有任何意义,没有其他方法可以指定localhost,而我只是不能使用API​​.

It makes no sense, there's no other way to specify the localhost, and I just can't use the API.

推荐答案

在我看来,这是两方面的问题.

In my case it was two-side problem.

  1. 需要将来源添加到Google控制台.

  1. Need to add origin to google console.

原产地如何? http://localhost

清除缓存.

有时这不起作用,您可能开始认为这不是缓存问题.详细信息如下.

This sometimes does not work and you may start thinking that this is not a cache problem. Details below.


1.如何将您的来源添加到Google控制台?

  • 转到此处: https://console.cloud.google.com/apis/credentials
  • 在顶部选择一个需要的项目.
  • 找到OAuth 2.0 client IDs,然后在此部分中选择(或创建)客户端ID.
  • 在打开的窗口中找到Restrictions -> Authorized JavaScript origins部分,并添加http://localhosthttp://localhost:8000(指定所需的端口).
  • Go here: https://console.cloud.google.com/apis/credentials
  • Select a Project you need at the top.
  • Find OAuth 2.0 client IDs and in this section select (or create) a client ID.
  • In the opened window find the section Restrictions -> Authorized JavaScript origins and add either http://localhost or http://localhost:8000 (specifying the port you need).

2.清除缓存.

如果步骤1不能解决问题,则需要清除缓存.

If the step #1 did not solve the problem, you need to clear cache.

如果您只想删除localhost缓存,则可以在Chrome中以以下方式进行操作:

If you want to remove just localhost cache, in Chrome you can do it in the next way:

  • 打开设置->更多工具->开发人员工具;
  • 右键单击重新加载"按钮->清空缓存并重新加载".

有时无法清除缓存.为了确保它仍然是缓存问题,请使用隐身模式打开浏览器,然后再次检查您的网站.

Sometimes cache clearing does not work. Just to be sure, that it is still a cache problem, open a browser using Incognito mode and check your site again.

这篇关于如何解决"idpiframe_initialization_failed"问题?对于本地主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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