我试图在登录时将基本的谷歌帐户信息(姓名、电子邮件、ID)捕获到数据库中。
我通过为他们的个人资料信息设置变量并通过 AJAX 更新数据库来做到这一点。
(参见下面示例中的变量)
if (authResult['access_token']) {
// The user is signed in
this.authResult = authResult;
helper.connectServer();
// After we load the Google+ API, render the profile data from Google+.
//this renders profile information to the page just fine
gapi.client.load('plus','v1',this.renderProfile);
var email = gapi.client.load('plus','v1',this.getEmail);
var acct_type = 'G';
var id = gapi.client.load('plus','v1',this.getId);
var fname = gapi.client.load('plus','v1',this.getFname);
var lname = gapi.client.load('plus','v1',this.getLname);
//DO AJAX!!
$.post("_google/processlogindata.php",
{
id:id,
fname:fname,
lname:lname,
email:email,
acct_type:acct_type
});
ajax 正在工作,它通过了硬代码'G'
并显示在数据库中。
当数据库默认值为 NULL 时,其余变量显示为空白条目。
我复制了renderProfile
因为它适用于在页面上显示配置文件位。例如,这就是 getFname 的样子(它们几乎相同):
getFname: function() {
var request = gapi.client.plus.people.get( {'userId' : 'me'} );
request.execute( function(profile) {
return profile.name.GivenName;
});},
如果我将此处的返回变量设置为“name”之类的静态字符串,它将显示在数据库中。所以问题肯定是我如何尝试访问或保存此个人资料信息。
所以我的问题是,如何将这些配置文件对象正确捕获到 AJAX 之上的变量?