使用 google 帐户登录无效

Sign in with google account not working

我正在尝试在我们的一个应用程序中包含 'Sign in Google account' 功能。我正在关注此文档 - https://developers.google.com/identity/sign-in/web/

我复制了整个 HTML 代码,只是用我的客户 ID 替换了那个客户 ID。

我的授权 JavaScript 来源是:http://localhost:80 授权重定向 URI 是:http://localhost/testing/test.php

我复制所有 HTML 代码的测试文件路径(由 google 文档给出)是“http://localhost/testing/esp.php

所以,当我执行 'esp.php' 文件时,我得到了 google 登录按钮。单击该按钮后,我会弹出使用 gmail id 登录的窗口。但是,登录后弹出窗口就消失了,我没有得到任何进一步的信息。

在我的浏览器控制台中我也没有得到任何东西。我相信我应该摆脱下面的 javasctip 代码。

console.log("ID: " + profile.getId()); // Don't send this directly to your server!
console.log("Name: " + profile.getName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());

知道我哪里做错了吗?

我终于解决了这个问题。我犯的错误是 - 我创建了一个简单的 API 密钥而不是 OAuth API KEY.

然后在授权 JavaScript 来源处我给出了“http://localhost:80". It should be the host name like "http://localhost”。

再次代替 'Authorized redirect URIs' 部分,它应该是“http://localhost/oauth2callback”。

就是这样 & 它会完成剩下的魔法...;)