Javascript 如何使用FB.ui({method:';apprequests';
如何获取用户的Facebook好友的姓名? 我使用Javascript 如何使用FB.ui({method:';apprequests';,javascript,facebook,sdk,friend,Javascript,Facebook,Sdk,Friend,如何获取用户的Facebook好友的姓名? 我使用FB.ui({method:'apprequests'? 这是我的密码: 函数FBUISelectFriends() { var selectedFriendsRequest\u ID; ui({method:'apprequests',message:'Select friends',data:'tracking information for the user',tite:'Select friends'}, 功能(响应){ 如果(!res
FB.ui({method:'apprequests'?
这是我的密码:
函数FBUISelectFriends()
{
var selectedFriendsRequest\u ID;
ui({method:'apprequests',message:'Select friends',data:'tracking information for the user',tite:'Select friends'},
功能(响应){
如果(!response | |!response.request_id){alert('request not sent');return;}
selectedFriendsRequest\u ID=response.request\u ID;
对于(变量i=0;i
我尝试了此代码,但无效:
FB.api(selectedFriendsRequest_ids[0], function (response) {console.log(response.name);});
你能帮忙吗
谢谢。自9月30日以来,Facebook发布了一个请求2.0实现他们的系统,这比以前的系统有用得多。 原因如下:
- 使用旧的,您的用户首先发送请求,Facebook将请求ID返回给您,然后您必须验证您向谁发送了请求
- 使用新的,对于每组请求(如用户使用多好友选择器发送多个请求),Facebook将返回一个请求id(参数:response.request)和一个包含所有Facebook用户id请求的参数(参数:response.to)
FB.api('/me/friends?fields=id、name、first\u name、last\u name
),您只需使用发送请求的Facebook用户id解析此请求的结果
这里对Requests 2.0的所有内容进行了解释:只需在函数中更改此项即可 函数FBUISelectFriends() { 一个文件getfriendfbname.php,它使用php中的好友facebook id返回facebook好友名称的名称
如何在应用程序仪表板中激活Requests 2.0?请查看我文章末尾链接中的性能改进部分:)
FB.ui(
{
method: 'apprequests',
redirect_uri: 'YOUR APP URL',
message: "Tom sent you a request"
},
function(response) {
if(response && response.hasOwnProperty('to')) {
for(i = 0; i < response.to.length; i++) {
//alert( response.to[i]);
// response.to[i] gives the selected facebook friends ID
// To get name of selected friends call this function below
getfbnames(response.to[i]);
}
}
}
);
var url = 'getfriendfbname.php'; // call a php file through URL and jquery ajax
$.ajax({
type:'POST',
url: url,
data : { fbid : selectedfrndid },
async: false,
success: function(data)
{
alert(data);
}
}); // end of ajax
}
$fbid=$_POST['fbid'];
$json = file_get_contents('https://graph.facebook.com/'.$fbid);
$data = json_decode($json);
echo $data->name;
return $data->name;