Google SignIn2 不会调用 onsuccess 回调 [英] Google SignIn2 won't call the onsuccess callback

查看:44
本文介绍了Google SignIn2 不会调用 onsuccess 回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gapi.signin2.render"功能在我的页面上放置了一个谷歌登录按钮.我向这个函数传递了一个带有 onsuccess 处理程序的对象.

I put a google signin button on my page using the "gapi.signin2.render" function. To this function I pass an object with the onsuccess handler.

当用户最初点击按钮时,一切都按预期工作.出现谷歌登录弹出窗口.但是在完成登录过程后,我的页面上没有任何反应.

When the user initially clicks on the button everything works as expected. The google signin popup appears. But after finishing the signin process nothing happens on my page.

刷新页面后,按钮再次触发认证过程.一旦登录"出现,onsuccess 处理程序就会被调用.

After refreshing the page, the button triggers the auth process again. And as soon as the "Signed In" appears, the onsuccess handler gets called.

我查看了网络流量并看到了包含所有信息的响应.这意味着一切都应该在谷歌控制台中正确配置.否则我不会得到回应,对吧?

I looked at the network traffic and saw a response containing all the information. That means that everything should be configured correctly in the google console. Otherwise I wouldn't get the response, right?

这是我的 vue 组件:

This is my vue component:

<template>
  ...
  <div id="google-signin-button" class="g-signin2"></div>
  ...
</template>

<script>
  ...
  window.gapi.signin2.render('google-signin-button', {
     onsuccess: this.onSignIn,
  })
  ...
  onSignIn: function(googleUser) { }
<script>

这是 index.html:

This is the index.html:

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

如何在初始登录时调用 onsuccess 处理程序?

What can I do to get the onsuccess handler called on the initial signin?

推荐答案

好的,我找到了.不幸的是,我误解了官方文档.

Ok, i found it. Unfortunately i misunderstood the official documentation.

我必须先加载 auth2 模块:

I had to load the auth2 module first:

window.gapi.load('auth2', () =>  {
  window.gapi.signin2.render('google-signin-button', {
    onsuccess: this.onSignIn,
  })
})

这篇关于Google SignIn2 不会调用 onsuccess 回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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