Javascript Google登录-未定义Google用户

Javascript Google登录-未定义Google用户,javascript,html,google-signin,google-identity,Javascript,Html,Google Signin,Google Identity,为了创建一个登录系统,我一直在遵循谷歌登录教程,现在我有了一个登录按钮,可以加载小部件来选择登录。单击后,应加载此函数: function onSignIn(googleUser) { var profile = googleUser.getBasicProfile(); console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead. console.log

为了创建一个登录系统,我一直在遵循谷歌登录教程,现在我有了一个登录按钮,可以加载小部件来选择登录。单击后,应加载此函数:

function onSignIn(googleUser) {
  var profile = googleUser.getBasicProfile();
  console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
  console.log('Name: ' + profile.getName());
  console.log('Image URL: ' + profile.getImageUrl());
  console.log('Email: ' + profile.getEmail());
}
但是,一旦我选择了帐户并登录,什么都不会发生。在开发者控制台中,当我输入“googleUser”时,它只会说:

未捕获引用错误:未定义googleUser

以下是我的全部代码:


S6C管理面板
S6C管理面板
返回S6C网站
函数回溯(){
window.location.href=”http://s6c.org";
}
函数onSignIn(谷歌用户){
var profile=googleUser.getBasicProfile();
console.log('ID:'+profile.getId());//不要发送到后端!改用ID令牌。
log('Name:'+profile.getName());
log('Image URL:'+profile.getImageUrl());
log('Email:'+profile.getEmail());
}

尝试添加其他元数据:

<meta name="google-signin-client_id" content="451815931731-u24ino5uecga1arf65814fd72201fcmu.apps.googleusercontent.com">
<meta name="google-signin-cookiepolicy" content="single_host_origin" />
<meta name="google-signin-requestvisibleactions" content="https://schema.org/AddAction" />
<meta name="google-signin-scope" content="https://www.googleapis.com/auth/plus.login" />


并确保在您的google Api管理器中,在凭证中,在OAuth 2.0客户端ID中,检查您的授权JavaScript源代码,确保您进入您的页面运行的源代码站点。如果您在localhost中开发add作为您的源代码脚本。

我也遇到了同样的问题,使用的技巧我成功地解决了这个问题

解决方案:

function onSignIn() {
  const googleUser = gapi.auth2.getAuthInstance().currentUser.get();
  const profile = googleUser.getBasicProfile();

  // do stuff here
}

gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse()的结果是什么?(登录后)。当我将其输入到开发人员控制台时,它只是在新行上打印“Object{}”,奇怪的是它不起作用。既然你使用的是网络组件,你有没有选择?不,很遗憾,我的测试中没有,作业只剩下一周了,所以我放弃了它,因为它不需要通过!Cheers ThoughAddOnFailure回调以登录按钮
函数onFailure(error){console.log(error)}
并查看返回的错误这是自OAUTH v2以来获取配置文件的正确方法