2013-08-26 69 views
2

我想访问使用Google+ API登录我的网站的用户的user_name/email_id。到目前为止,我已经实现了Google+ API和返回值是:使用Google+ API登录后获取电子邮件ID /用户名

User Logged In This is his auth tokenya29.AHES6ZRWhuwSAFjsK9jYQ2ZA73jw9Yy_O2zKjmzxXOI8tT6Y 

如何使用该工具来获取用户名/电子邮件ID?

回答

1

,如果你正确地登录,这是足以称之为借助Google+ API,在这个网址:

GET https://www.googleapis.com/plus/v1/people/me 

其中userId具有特殊的价值me,让所有有关记录的用户信息。欲了解更多信息,请参阅: https://developers.google.com/+/api/latest/people/get

0

我正在添加一个代码示例以帮助其他人。

在这种情况下,对谷歌的请求的电子邮件进行登录操作,以及像名用户的个人资料信息,....一旦这些信息被检索,则执行到我自己的登录服务的请求:

 function OnGoogle_Login(authResult) { 
        if (authResult['access_token']) { 
         gapi.client.load('oauth2', 'v2', function() 
         { 
          gapi.client.oauth2.userinfo.get().execute(function(userData) 
          { 
           $("#frmLoginGoogle input[name='id']").val(userData.id); 
           $("#frmLoginGoogle input[name='name']").val(userData.name); 
           $("#frmLoginGoogle input[name='email']").val(userData.email); 
           $.ajaxSetup({cache: false}); 
           $("#frmLoginGoogle").submit(); 
          }); 
         }); 
        } 
       } 

     $(document).ready(function() { 

      /** GOOGLE API INITIALIZATION **/ 
      $.ajaxSetup({cache: true}); 

      $.getScript("https://apis.google.com/js/client:platform.js", function() { 
          $('#btnLoginGoogle').removeAttr('disabled'); 
         }); 

      $("#btnLoginGoogle").click(function() { 
         gapi.auth.signIn({ 
          'callback': OnGoogle_Login, 
          'approvalprompt': 'force', 
          'clientid': 'XXXXX.apps.googleusercontent.com', 
          'scope': 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email', 
          'requestvisibleactions': '', 
          'cookiepolicy': 'single_host_origin' 
         }); 
        }); 
     }); 
相关问题