这是我的初始化代码:
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
}
});
}
这给了我以下错误消息:
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。事情是,在every堆栈溢出/参考我发现他们已经指定了Authorised JavaScript origins
and Authorised redirect URIs
我必须使用http://localhost
代替http://127.0.0.1
。如果我这样做,我会收到该错误和Permission denied to generate login hint for target domain.
如果我尝试登录。
如果我使用http://127.0.0.1
在两者上,我都没有idpiframe_initialization_failed
在初始化时,但当我尝试登录时得到相同的权限被拒绝。
这是没有意义的,没有其他方法可以指定本地主机,而且我无法使用 API。
就我而言,这是两个方面的问题。
-
需要将 origin 添加到 google 控制台。
起源是什么样子的?http://localhost
-
清除缓存。
有时这不起作用,您可能会开始认为这不是缓存问题。详细信息如下。
1. 如何将你的origin添加到google console?
- 到这里:https://console.cloud.google.com/apis/credentials
- 在顶部选择您需要的项目。
- Find
OAuth 2.0 client IDs
并在此部分中选择(或创建)客户端 ID。
- 在打开的窗口中找到该部分
Restrictions -> Authorized JavaScript origins
并添加http://localhost
or http://localhost:8000
(指定您需要的端口)。
2.清除缓存。
如果步骤 #1 没有解决问题,您需要清除缓存。
如果您只想删除localhost
缓存,在Chrome
你可以通过以下方式做到这一点:
- 打开设置->更多工具->开发者工具;
- 右键单击“重新加载”按钮 - >“清空缓存并硬重新加载”。
有时清理缓存不起作用。为了确定这仍然是缓存问题,请使用隐身模式打开浏览器并再次检查您的网站。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)