2014-01-08 200 views
0

獲取用戶數據我使用的JavaScript SDK使用Facebook登錄,但我現在連接,我不知道如何捕捉用戶的數據併發送一個笨控制器上。我決定使用AJAX,但我不知道如何實現它,如果我還沒有我的Facebook用戶數據。使用Facebook的登錄啓用JavaScript SDK

if (response.status === 'connected') { 

//How do I get userdata?? 
// I decided to use ajax 

$.ajax({ 
    type : 'POST', 
    data : 'userdata='+ //but I don't know how I would put my data, 
    url : '<?php echo site_url("somecontroller/somefunction");?>', 
    success : function(){ 

    } 
}); 

} 

而且,我怎麼得到的數據被放置在一個陣列,從而將其發送到我的控制器時,我可以只使用1個變量?

回答

1

後你驗證,如果用戶連接您CURENT用戶訪問Facebook的API:

FB.api('/me', function(info) { 
//for example facebook id for curent user 
var id = info.id; 
//you can view all data which you can use, if you need more data ask for more permisson 
console.log(info); 

//here you can ajax data for your need 

$.ajax({ 
    type : 'POST', 
    data : info, //all data 
    url : '<?php echo site_url("somecontroller/somefunction");?>', 
    success : function(){ 

    } 
}); 

//or only date which you need 

$.ajax({ 
    type: "POST", 
    url: '<?php echo site_url("somecontroller/somefunction");?>', 
    data: { id: info.id, fullname: info.name }, 
    success : function(){ 

    } 
}) 

}); 
0
if (response.status === 'connected') { 
    var userId = response.authToken.userID; 
    FB.api('/'+userId, function(response) { 
    // response contain user's public data 
    }); 
} 

雖然,如果u想要得到比公開數據的詳細信息,u必須使用來獲得用戶的許可的FB.login

相關問題