2013-07-12 211 views
0

我正在玩Google Plus API。我想创建一个使用服务器端的过程,存储用户的详细信息到我的数据库基本应用:Google Plus身份验证 - Ajax令牌

https://developers.google.com/+/web/signin/server-side-flow

目前我到第6步。我的按钮在页面上出现,我可以使用ajax将code(id)发送到服务器。喜欢的东西:

var dataString = 'auth= ' +authResult['code']; 

// Send the code to the server 
$.ajax({ 
    type: 'POST', 
    url: 'storeToken', 
    dataType: 'html', 
    data: dataString, 
    processData: false, 
    statusCode: { 
     200: function(result){ 
      $('#test').html(result); 
       if (result['profile'] && result['people']){ 
        $('#test').html('Hello ' + result['profile']['displayName'] + '. You successfully made a server side call to people.get and people.list'); 
       } else { 
        $('#test').html('Failed to make a server-side call. Check your configuration and console.'); 
       } 
     } 

    }, 
}); 

现在的文件,它说,我应该转换到code和ACCESS_TOKEN refresh_token - 然而,这是我似乎无法做到的部分...

我在哪里ajax发布到,我可以使用$ code从上面的脚本成功传递。我试过了:

$client = new Google_Client(); 
$client->authenticate($code); 

但是从这里我不知道该怎么做。文档在响应中提到它可以使用:result['profile']['displayName']但是,我不知道它是如何工作的。

回答