【发布时间】:2015-04-17 13:29:53
【问题描述】:
我正在尝试在我的网站上放置一个 Google+ 登录按钮。该按钮完美运行。我也有一个退出按钮。我在用户登录时隐藏了登录按钮。我的代码在这里:
<span id="signinButton">
<span
class="g-signin"
data-callback="signinCallback"
data-clientid="******************"
data-cookiepolicy="single_host_origin"
data-requestvisibleactions="http://schema.org/AddAction"
data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email">
</span>
</span>
<button id="revokeButton" onclick="gapi.auth.signOut()">Sign Out</button>
<script>
function signinCallback(authResult) {
if (authResult['status']['signed_in']) {
document.getElementById('signinButton').setAttribute('style', 'display: none');
console.log("User successfully logged in!!");
} else {
console.log('Sign-in state: ' + authResult['error']);
}
}
</script>
<script>
function disconnectUser(access_token) {
var revokeUrl = 'https://accounts.google.com/o/oauth2/revoke?token=' +
access_token;
// Perform an asynchronous GET request.
$.ajax({
type: 'GET',
url: revokeUrl,
async: false,
contentType: "application/json",
dataType: 'jsonp',
success: function(nullResponse) {
document.getElementById('signinButton').setAttribute('style', 'display: display');
// The response is always undefined.
console.log("Success in logging out!");
},
error: function(e) {
// Handle the error
console.log(e);
// You could point users to manually disconnect if unsuccessful
// https://plus.google.com/apps
}
});
}
</script>
问题是当我使用 gapi.auth.signOut() 注销时...它会注销我,但刷新时再次将同一用户登录到 Google+。如何允许其他人登录我的网站。如何从 Google 完全注销人员。我是 Javascript 新手...举个例子会有所帮助。
【问题讨论】:
-
你是在页面加载时调用登录函数吗?
-
否..仅当单击 signinButton 时..当我单击按钮时...出现一个对话框并消失...这意味着以前的用户已登录。
-
我的第一个问题是:您打算让您的网站成为用户登录和退出 google+ 的代理,还是打算使用 google+ 作为授权帐户创建访问的一种方式到您的网站?如果我访问 someSite.com 并使用 google+ 登录,然后退出该站点,我不会期望实际退出我的 google+ 帐户。可能是因为 google 正在执行一项规则,即第三方网站不能让用户退出 google+。
-
嗯,刷新后一定有什么东西试图让用户登录。如果您的页面上还有 Google-API javascript,请将其添加到您的问题中。
-
好吧,我想我的下一个问题是,如果您没有捕获和保存数据以与您网站的唯一身份访问者相关联,那么他们为什么还要登录呢?在我看来,也许是天真的,就像这样无缘无故地限制用户。是否打算向 g+ 用户授予其他方式不可用的特殊内容?