dongqianwei6664 2013-10-06 16:45
浏览 30
已采纳

如何制作Facebook FQL查询以选择所有朋友

I'm new with PHP SDK Facebook, so sorry if that quesiton is stupid.

So, i have this code

SELECT name FROM user
    WHERE current_location.country = 'Italy' AND
    uid IN (
        SELECT uid2 FROM friend WHERE uid1 = me()
    ) 

That responses me:

{
  "data": [
    {
      "name": "Matilde xxxx"
    }, 
    {
      "name": "Samson xxxxxxxx"
    },  
    {
      "name": "Emanuela xxxxxxx"
    }
  ]
}

I'm using this site to analyze how to manage the json :http://chris.photobooks.com/json/default.htm

i saw that if i want to have a request of the name of a friend i have to do that: root.data[5].name

so that is my php code :

$user_id = $facebook->getUser();


$all_friends = $facebook->api(array('method' => 'fql.query', 'query' => 'SELECT name FROM user
        WHERE current_location.country = "Italy" AND
        uid IN (
            SELECT uid2 FROM friend WHERE uid1 = 1068943079
        ) '));
        $val = 1;
        echo $all_friends['data'][$val]['name'];

(is a test, i want to see the friend at key=1) but there is only white page... show nothing.. and if i do echo $all_friends i see Array.

Sorry if this is a stupid question, i know that i can use another method to do that..but i want to know how to do it with this way! Thank you, and sorry for my language.

That is all my code : CLICK HERE TO SEE MY CODE

  • 写回答

1条回答 默认 最新

  • dongyuan7110 2013-10-06 16:53
    关注

    1. You should print_r($all_friends) to check the structure of the array

    Try

    echo $all_friends[$val]['name'];
    

    2. The FQL query should only occur when $user != 0.

    Place it under the if statement

    3. You didn't ask for the read_friendlists permission

    $params = array(
      'scope' => 'read_friendlists'
    );
    
    $loginUrl = $facebook->getLoginUrl($params);
    

    Doc:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图