我想访问使用Google+ API登录我的网站的用户的user_name
/email_id
。到目前为止,我已经实现了Google+ API和返回值是:使用Google+ API登录后获取电子邮件ID /用户名
User Logged In This is his auth tokenya29.AHES6ZRWhuwSAFjsK9jYQ2ZA73jw9Yy_O2zKjmzxXOI8tT6Y
如何使用该工具来获取用户名/电子邮件ID?
我想访问使用Google+ API登录我的网站的用户的user_name
/email_id
。到目前为止,我已经实现了Google+ API和返回值是:使用Google+ API登录后获取电子邮件ID /用户名
User Logged In This is his auth tokenya29.AHES6ZRWhuwSAFjsK9jYQ2ZA73jw9Yy_O2zKjmzxXOI8tT6Y
如何使用该工具来获取用户名/电子邮件ID?
,如果你正确地登录,这是足以称之为借助Google+ API,在这个网址:
GET https://www.googleapis.com/plus/v1/people/me
其中userId
具有特殊的价值me
,让所有有关记录的用户信息。欲了解更多信息,请参阅: https://developers.google.com/+/api/latest/people/get
具体用于获取认证的用户的电子邮件地址,请记住,你将需要包括userinfo.email范围,并向tokeninfo端点的呼叫。欲了解更多信息,请参阅https://developers.google.com/+/api/oauth#scopes。
我正在添加一个代码示例以帮助其他人。
在这种情况下,对谷歌的请求的电子邮件进行登录操作,以及像名用户的个人资料信息,....一旦这些信息被检索,则执行到我自己的登录服务的请求:
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'
});
});
});