使用 Google+ 登录时如何注销 [英] How To Sign Out Using When Using Google+ Sign-In

查看:30
本文介绍了使用 Google+ 登录时如何注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google 在此处记录 gapi.auth.signOut() 方法:https://developers.google.com/+/web/signin/#sign-out

Google documents there gapi.auth.signOut() method here: https://developers.google.com/+/web/signin/#sign-out

问题是它说您只能在 signinCallback 触发后调用该方法.据我所知,触发 signinCallback 的唯一方法是在页面上放置一个登录按钮.

The catch is that it says you can only call that method after the signinCallback has fired. So far as I can tell, the only way to fire the signinCallback is to put a sign-in button on the page.

这在我的登录页面上非常有效,但是一旦我对用户进行了身份验证,就无需在后续页面上放置 G+ 登录按钮.我只想在角落里有一个小的注销"链接,用户可以点击它来注销.

This works great on my sign-in page itself, but as soon as I've authenticated a user, there's no need to put the G+ sign-in button on subsequent pages. I just want to have a small 'log out' link in the corner that the user can click to sign-out.

我尝试让我的注销链接调用 gapi.auth.signOut() 但它什么也没做,除非我还显示了一个无用的登录按钮.我如何让它发挥作用?

I tried having my log-out link call gapi.auth.signOut() but it does nothing unless I am also showing a useless log-in button. How do I get this to work?

推荐答案

按钮只需在 DOM 中,不必显示.似乎效果很好的是:

The button just has to be in the DOM, it doesn't have to be showing. What seems to work well is:

  1. 创建一个隐藏元素并使用 gapi.signin.render 附加 gapi 处理程序
  2. 等待immediate_failed 错误 - 然后显示按钮
  3. 否则,接受登录回调,并显示注销按钮

然后你每次都会收到回调,但只有在退出时才会显示按钮.

Then you'll get a callback every time, but only show the button when signed out.

这篇关于使用 Google+ 登录时如何注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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