当用户已经登录时,如何避免出现谷歌登录弹出窗口
How to avoid the google Sign In Pop up when the user is already logged in?
我使用以下代码让用户通过谷歌登录。
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css">
<script src="https://apis.google.com/js/api:client.js"></script>
<script>
var googleUser = {};
var startApp = function () {
gapi.load('auth2', function () {
// Retrieve the singleton for the GoogleAuth library and set up the client.
auth2 = gapi.auth2.init({
client_id: [my client id],
cookiepolicy: 'single_host_origin',
// Request scopes in addition to 'profile' and 'email'
scope: 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.me'
});
});
};
function checkUser() {
if (auth2.isSignedIn.get()) {
onSignIn(auth2.currentUser.po.po);
}
else {
gapi.auth.authorize({ client_id: [my client id], scope: 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.me', immediate: false }, onSignIn);
}
}
function onSignIn(googleUser) {
alert('Access Token' + googleUser.access_token);
//location.href = "ServerSide.aspx?acccessToken=" + googleUser.access_token;
}
</script>
<style type="text/css">
#customBtn {
display: inline-block;
background: #4285f4;
color: white;
width: 190px;
border-radius: 5px;
white-space: nowrap;
}
#customBtn:hover {
cursor: pointer;
}
span.label {
font-weight: bold;
}
span.icon {
/*background: url('/identity/sign-in/g-normal.png') transparent 5px 50% no-repeat;*/
display: inline-block;
vertical-align: middle;
width: 42px;
height: 42px;
border-right: #2265d4 1px solid;
}
span.buttonText {
display: inline-block;
vertical-align: middle;
padding-left: 42px;
padding-right: 42px;
font-size: 14px;
font-weight: bold;
/* Use the Roboto font that is loaded in the <head> */
font-family: 'Roboto', sans-serif;
}
</style>
<!-- In the callback, you would hide the gSignInWrapper element on a
successful sign in -->
<div id="gSignInWrapper" onclick="checkUser()">
<span class="label">Sign in with:</span>
<div id="customBtn" class="customGPlusSignIn">
<span class="icon"></span>`enter code here`
<span class="buttonText">Google</span>
</div>
</div>
<div id="name"></div>
<script>startApp();</script>
有了这段代码,如果用户登录谷歌,弹出窗口就会来来去去,这看起来很奇怪。所以我想如果用户登录谷歌弹出不应该来,直接让用户进入系统。为此,我在点击按钮时使用了"auth2.isSignedIn.get()",但即使用户登录到谷歌,这个函数也总是给我false。我陷入了困境。如果你有任何方法可以实现这一点,请告诉我。
isSignedIn方法可在google身份验证实例GoogleAuth.isSignedIn.get()上使用,您应该使用以下
gap.auth2.getAuthInstance().isSignedIn.get()
相关文章:
- 谷歌登录弹出并立即关闭
- 谷歌登录按钮
- 如何通过谷歌身份工具包修改登录按钮?(节点.js)
- 谷歌登录按钮的宽度和高度问题
- 访问谷歌登录函数 Angular 2 中的构造函数参数
- 谷歌登录无法识别登录 角度中的回调功能
- 使用谷歌登录api-管理用户权限
- 使用谷歌登录网页时使用的身份验证令牌是什么
- 获取所有用户's的联系人列表(包括电话号码)来自javascript中的谷歌登录
- 谷歌登录成功功能在我阻止第三方cookie时没有任何作用
- 我需要在同一页面上同时使用“使用谷歌登录”和“使用谷歌注册”按钮
- 使用谷歌分析跟踪登录的用户活动
- 如何在没有登录按钮的情况下初始化谷歌登录
- 带有谷歌登录的火狐插件
- 成功登录谷歌后加载页面
- 谷歌身份验证在登录时不会显示弹出窗口
- 谷歌登录扩展令牌
- 如何获得用户's的电子邮件在METEOR.js中登录谷歌
- 通过应用程序登录谷歌账户
- 隐藏登录谷歌's "欢迎回来,{name}"