dthdlv9777 2014-10-12 00:25
浏览 48
已采纳

阅读PHP Facebook Graph api SDK的结果

I am trying to get a list of all the names & id of people actually going to an event I create. Getting the list using the php graph api for facebook was the easy part and seems to work.

Code (php) the get the data:

//GET ATTENDING

    $getattending = "/" . $event_id . "/attending?fields=name,id";

    $req_events = new FacebookRequest($session, 'GET', $getattending);
    $req_response = $req_events->execute();
    $data_array = $req_response->getGraphObject()->asArray();

    $counter = array_map("count", $data_array);
    $count = $counter['data'];

    echo "Attending: $count<BR>";

   echo "<PRE>";
   print_r($data_array);
   echo "</PRE>";

The result:

Array (

[data] => Array
    (
        [0] => stdClass Object
            (
                [name] => Thierry Martens
                [id] => 788923242
            )

        [1] => stdClass Object
            (
                [name] => Lisa Mario Laurier
                [id] => 708876902536391
            )

        [2] => stdClass Object
            (
                [name] => Ramy Mahfoudhi
                [id] => 735036479911364
            )

        [3] => stdClass Object
            (
                [name] => Jeremy Verriest Duroisin
                [id] => 783108468420824
            )

        [4] => stdClass Object
            (
                [name] => Jonas En Svetlana Laurier
                [id] => 773139856081632
            )

        [5] => stdClass Object
            (
                [name] => Maxime Demerliere
                [id] => 849400761761008
            )

        [6] => stdClass Object
            (
                [name] => Jeremy Beauchamp
                [id] => 10204174155667109
            )

        [7] => stdClass Object
            (
                [name] => Sari Jens Delcourte Delusinne
                [id] => 10204086515874904
            )

        [8] => stdClass Object
            (
                [name] => Pieter Marysse
                [id] => 10204911283045115
            )

        [9] => stdClass Object
            (
                [name] => Patrick Vanden Bosschelle
                [id] => 10202907209181148
            )

    )

BUT i am having problems to actually gather the data itsels; i simply need the name and the id in simple array or list so i can use it in the rest of the script. Any ideas Anyone?

My second question is the php graph api seems to have a "/eventnr/attending" thing for graph 2.1; showing nr attendants to your event in question; but when i actually call it i get an error stating i need to use graph 2.1 while i uploaded the latest php sdk and can't seem to find a way to change that version. This question is not as important as the one above; but if it works i would need less code :)

Hope you guys can help me :)

  • 写回答

3条回答 默认 最新

  • doumu4916 2014-10-12 10:57
    关注

    !!!! GOT IT !!!!

    Did look some further on here and the solutions seems to be pretty easy:

    for ($x = 0; $x <= $count; $x++)
            {
            $names[$x] = $data_array['data'][$x]->name;
            $ids[$x] = $data_array['data'][$x]->id;
            }
    

    Displays:

    $names array:

    Array ( [0] => Thierry Martens [1] => Lisa Mario Laurier [2] => Ramy Mahfoudhi [3] => Jeremy Verriest Duroisin [4] => Jonas En Svetlana Laurier [5] => Maxime Demerliere [6] => Jeremy Beauchamp [7] => Sari Jens Delcourte Delusinne [8] => Pieter Marysse [9] => Patrick Vanden Bosschelle [10] => )

    $ids array:

    Array ( [0] => 788923242 [1] => 708876902536391 [2] => 735036479911364 [3] => 783108468420824 [4] => 773139856081632 [5] => 849400761761008 [6] => 10204174155667109 [7] => 10204086515874904 [8] => 10204911283045115 [9] => 10202907209181148 [10] => )

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料