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 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历