【问题标题】:Facebook Graph API get average amount of users "friends of friends" using fqlFacebook Graph API 使用 fql 获取平均数量的用户“朋友的朋友”
【发布时间】:2013-06-03 17:38:30
【问题描述】:

我正在尝试计算好友好友的平均数量

例如,如果用户有 4 个朋友:

  1. 朋友 A 和 5 个朋友
  2. 朋友 B 和 10 个朋友
  3. 朋友 C 和 15 个朋友
  4. 朋友 D 的朋友数量未知(假设此信息对用户不可见)

结果会

  • 平均好友数 = 10
  • 计算的朋友数 = 3
  • 好友总数 = 4;

为此使用 PHP 和 FQL 和 Graph API

问题是我认为我发送的 fql 批处理请求是 2 大,我没有得到响应

如果有人知道更好的/工作方法来做到这一点,请帮助

我的代码 sn-p:

        //get average of friends friends
        $friends=$facebook->api('/me?fields=friends');
        $friends=$friends['friends'];
        if (isset($friends)){
            //now we have array of friends
            $friends = $friends['data'];
            //prepare the query
            $queries = array();
            foreach ($friends as $friend){
                $friendId = $friend['id'];
                $query1="SELECT friend_count FROM user WHERE uid = $friendId";
                $newArray = array('method'=>'GET', 'relative_url'=>'method/fql.query?query='.str_replace(' ','+',$query1));
                $queries[]=$newArray;
            }
            //send batch request
            $batchResponse = $facebook->api('/?batch='.json_encode($queries), 'POST');

            //go over all responses get the amount of friends

            var_dump ($batchResponse); //this is null ... think the request fails beacuse of its size

【问题讨论】:

    标签: php facebook facebook-graph-api facebook-fql facebook-apps


    【解决方案1】:

    不需要对用户的每个朋友都进行批量请求,而是可以使用下面的嵌套查询来做同样的事情,

    SELECT friend_count FROM user WHERE uid in (SELECT uid2 from friend where uid1=me())
    

    【讨论】:

      猜你喜欢
      • 2011-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多