Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何实现googleplus登录API_Javascript_Html_Google Plus - Fatal编程技术网

Javascript 如何实现googleplus登录API

Javascript 如何实现googleplus登录API,javascript,html,google-plus,Javascript,Html,Google Plus,很长一段时间以来,我一直试图在我的html页面中实现google plus登录api。到目前为止,我还没有取得任何成功。我已经能够呈现一个按钮作为gmail登录。但是,我不知道如何从google plus服务器获取用户信息。 请检查我下面的代码,并建议我如何获取用户信息 <script type="text/javascript"> (function() { var po = document.

很长一段时间以来,我一直试图在我的html页面中实现google plus登录api。到目前为止,我还没有取得任何成功。我已经能够呈现一个按钮作为gmail登录。但是,我不知道如何从google plus服务器获取用户信息。 请检查我下面的代码,并建议我如何获取用户信息

              <script type="text/javascript">
              (function() {
                var po = document.createElement('script');
                po.type = 'text/javascript'; po.async = true;
                po.src = 'https://apis.google.com/js/client:plusone.js?onload=render';
                var s = document.getElementsByTagName('script')[0];
                s.parentNode.insertBefore(po, s);
                signinCallback(authResult);

              })();

              function render() {
                gapi.signin.render('gp', {
                  'callback': 'signinCallback()',
                  'clientid': 'I know my id goes here :P.apps.googleusercontent.com',
                  'cookiepolicy': 'single_host_origin',
                  'requestvisibleactions': 'http://schema.org/AddAction',
                  'scope': 'https://www.googleapis.com/auth/plus.login'
                });
              }

              function signinCallback(authResult) {
                  if (authResult['status']['signed_in']) {
                    // Update the app to reflect a signed in user
                    // Hide the sign-in button now that the user is authorized, for 

                  } else {
                    // Update the app to reflect a signed out user
                    // Possible error values:
                    //   "user_signed_out" - User is signed-out
                    //   "access_denied" - User denied access to your app
                    //   "immediate_failed" - Could not automatically log in the user
                    console.log('Sign-in state: ' + authResult['error']);
                  }
                }
              </script>

(功能(){
var po=document.createElement('script');
po.type='text/javascript';po.async=true;
po.src=https://apis.google.com/js/client:plusone.js?onload=render';
var s=document.getElementsByTagName('script')[0];
s、 parentNode.insertBefore(po,s);
signinCallback(authResult);
})();
函数render(){
gapi.signin.render('gp'{
“回调”:“signinCallback()”,
“clientid”:“我知道我的id在这里:P.apps.googleusercontent.com”,
'cookiepolicy':'single_host_origin',
“请求访问操作”:http://schema.org/AddAction',
'范围':'https://www.googleapis.com/auth/plus.login'
});
}
函数signinCallback(authResult){
如果(authResult['status']['signed_in']){
//更新应用程序以反映已登录的用户
//现在用户已获得授权,隐藏“登录”按钮,例如
}否则{
//更新应用程序以反映已注销的用户
//可能的错误值:
//“用户已注销”-用户已注销
//“拒绝访问”-用户拒绝访问您的应用
//“立即\u失败”-无法自动登录用户
log('登录状态:'+authResult['error']);
}
}

你显然走对了方向。在
signicallback
方法中,在确认用户已登录的第一种情况下,可以对各个plus端点进行方法调用,以获取所需信息。例如,这应该在该块中起作用:

gapi.client.plus.people.get({
  'userId' : 'me'
}).execute(function(resp) {
  console.log('Display Name: ' + resp.displayName);
});

仅供参考,客户端ID是公共的,因此无需删除它。