Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用FB.ui({method:';apprequests';_Javascript_Facebook_Sdk_Friend - Fatal编程技术网

Javascript 如何使用FB.ui({method:';apprequests';

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

如何获取用户的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'},
功能(响应){
如果(!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)
您只需在应用程序仪表板中激活Requests 2.0,然后更改Javascript回调中的条件即可

有人请求检索有关用户朋友的信息
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;