javascript - 使用 JS 退出 Google+

标签 javascript google-plus

我想在我的网站上放置一个 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> &nbsp;&nbsp;&nbsp;&nbsp;
<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+。我如何允许其他人登录到我的站点。我如何完全注销谷歌的人。我是 Javascript 的新手...举个例子会有帮助。

最佳答案

我想出的答案很简单。用户第一次登录时,他没有登录到我的站点。所以很明显,用户必须登录。下次页面刷新时...Google+ 检查用户是否已经登录任何 Google 服务,例如 gmail 等。如果答案为真,则让用户保持登录状态。要检查这是否有效...退出您的任何 Google 服务(gmail 等)并尝试使用 Google+ 登录。它将要求凭据。因此,一旦用户登录到 Google+,他/她就不需要每次都登录。

关于javascript - 使用 JS 退出 Google+,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29700641/

相关文章:

javascript - jQuery:将选择框值和文本转换为对象

javascript - 如何使用 javascript 将位图转换为图像?

audio - 使用 ffmpeg 编码声音以在 Google Hangouts 应用程序中播放

ios - GooglePlus 与 CocoaPods 链接错误

google-plus - Google+ API 定价

javascript - 如何检查日期字符串中是否已经有两个正斜杠?

java - 投票系统增加票数

javascript - 使用 Moment 按天合并每小时日期列表

google-app-engine - 使用 Google Cloud Endpoint (Java) 的内置身份验证时,如何获取当前用户的 Google+ 个人资料?

java - Plus.Builder.build() 抛出 java.lang.NoSuchFieldError : MAJOR_VERSION