2013-07-12 210 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']但是,我不知道它是如何工作的。

回答