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

查看:189
本文介绍了使用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处理程序附加到gapi.signin.render
  2. 等待Instant_Failed错误-然后显示按钮
  3. 否则,请接受登录的回调,然后显示注销按钮

然后,您每次都会收到回调,但仅在退出时显示按钮.

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

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

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