首页 > 解决方案 > Google+ API 未触发 onSignIn 调用

问题描述

我有一个 Angular 项目,我正在尝试创建一个按钮,允许用户登录到他们的 Google+ 帐户,以便获取用户名、电子邮件和个人资料图片等信息。我在这里遵循了本教程:

我在 index.html 页面中添加了以下内容:

<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">

然后我在我的 app.component.html 中添加了以下内容

<div class="g-signin2" data-onsuccess="onSignIn"></div>

然后我终于在我的 app.component.ts 中添加了这个回调函数:

  onSignIn(googleUser)  {
    let 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()); // This is null if the 'email' scope is not present.
  }

我的问题是由于某种原因永远不会调用 onSignIn 回调函数。关于为什么会这样的任何想法?如果您有任何问题,我会非常积极。

标签: angulargoogle-plus

解决方案


Google+ API 将于 2019 年 3 月 7 日关闭,因此我决定不集成此 API。在这里阅读更多


推荐阅读