检查在谷歌用户与谷歌签署签到 [英] Checking for signed in Google user with Google Sign-in

查看:183
本文介绍了检查在谷歌用户与谷歌签署签到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的谷歌工作签到库。

如果我使用谷歌的提供的登录按钮我的网页上,它很快改变状态,表明我登录,我采取任何行动之前。

If I use Google's provided sign in button on my page, it quickly changes states to show that I am logged in before I've taken any action.

是否有可能来检测这个国家没有签署使用谷歌的默认按钮?

Is it possible to detect this signed in state without using Google's default button?

主要的问题是,他们的按钮不允许检查登录的帐户托管域。

The main issue is that their button doesn't allow for checking for the hosted domain of the logged in account.

推荐答案

我试图使用 GoogleAuth.currentUser.get()函数来获取用户,但作为文档指出:

I was trying to use the GoogleAuth.currentUser.get() function to get the user, but as the documentation notes:

在一个新初始化GoogleAuth例如,当前用户尚未设置。使用currentUser.listen()方法或GoogleAuth.then()来获得一个初始化的GoogleAuth实例。

in a newly-initialized GoogleAuth instance, the current user has not been set. Use the currentUser.listen() method or the GoogleAuth.then() to get an initialized GoogleAuth instance.

使用 GoogleAuth.then(的OnInit,onFailure处)如上所述正确检索登录的用户的状态。

Using GoogleAuth.then(onInit, onFailure) as mentioned above correctly retrieves the logged in state of the user.

/**
 * The Sign-In client object.
 */
var auth2;

/**
 * Initializes the Sign-In client.
 */
var initClient = function() {
  gapi.load('auth2', function(){
    /**
     * Retrieve the singleton for the GoogleAuth library and set up the
     * client.
     */
    auth2 = gapi.auth2.init({
        client_id: CLIENT_ID,
        scope: 'profile'
    });

    // Called once auth2 has finished initializing
    auth2.then(checkForLoggedInUser, onFailure);

  });
};

function checkForLoggedInUser() {
  var user = auth2.currentUser.get();
  var profile = user.getBasicProfile();
  console.log('Email: ' + profile.getEmail());
}

这篇关于检查在谷歌用户与谷歌签署签到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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