解析Facebook的PHP API响应 - 修复版/回收2015年5月2日 [英] Parsing Facebook PHP API Response - Remastered / Recycled 05/02/2015

查看:198
本文介绍了解析Facebook的PHP API响应 - 修复版/回收2015年5月2日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的阵列;

  {
  生物:Facebook的测试生物 - >愣神忘记设置而试图获取该信息的测试我最新的Facebook应用!
  电影: {
    数据:
      {
        名:博物馆惊魂夜,
        ID:251922028320619
      },
      {
        名:小Nicky
        ID:112378985439799
      },
      {
        流派:动作/冒险/喜剧/家庭/科幻
        名:回到未来三部曲,
        ID:141545972523915
      },
      {
        流派:愚蠢的,
        名:公驴,
        ID:21295715752
      },
      {
        流派:喜剧
        名:布朗夫人的儿子们D'电影,
        ID:217475368404328
      },
      {
        流派:动画系列
        名:马达加斯加,
        ID:149800431712088
      },
      {
        类型:动画,
        名:冻结,
        ID:482368755113431
      },
      {
        类型:动画,
        名:玩具总动员,
        ID:10498014129
      },
      {
        流派:这是一个坚韧不拔的戏剧,发育成战胜逆境的故事令人振奋应该吸引广大的观众,男性和女性。
        名:摆脱了电影
        ID:135991503231501
      },
      {
        类型:动画,
        名:狮子王
        ID:12393266550
      },
      {
        流派:动画|喜剧|家庭
        名:卑鄙的我
        ID:117067844993952
      },
      {
        流派:动作/冒险
        名:雷神,
        ID:113589202010624
      },
      {
        名:史酷比:电影,
        ID:306089742863765
      },
      {
        流派:动作/童话,
        名:汉塞尔和放大器;格蕾特:女巫猎人,
        ID:271965656164363
      },
      {
        名:哈利·波特
        ID:156794164312
      },
      {
        名:星球大战,
        ID:216676368377759
      },
      {
        名:爪牙,
        ID:136787429687873
      },
      {
        名:博物馆奇妙夜2
        ID:115126478502712
      },
      {
        流派:动画,假日,家庭
        名:圣诞夜惊魂
        ID:173587329354820
      },
      {
        名:环太平洋
        ID:439835889373123
      },
      {
        流派:动作冒险
        名:遗忘英国
        ID:235958443193536
      },
      {
        流派:动画系列
        名:怪物史莱克,
        ID:355374000182
      },
      {
        名:史酷比:电影,
        ID:106352129401640
      },
      {
        流派:史诗动作冒险
        名:德古拉不为人知
        ID:332230740134829
      },
      {
        名:辛巴,
        ID:27665751322
      }
    ]
    分页:{
      下一个: \"https://graph.facebook.com/v2.2/663878750359892/movies?fields=genre,name&limit=25&offset=25&__after_id=enc_AezyAtvaN1UtcaRwF9kgU5Z5PIv07LU_3Wli-CRCkYEol9BoJJtn86fNGT4v-XsnG-o\"
    }
  },
  ID:663878750359892
}

我知道从我的阵列获得生物,然而这是pretty太少了onthe互联网如何从Facebook的API阵列上传递的第一级信息;

  $ FB_About_Bio = $ graph->的getProperty('生物');

然而,当涉及到要求电影;

  $ FB_About_Movies = $ graph->的getProperty('电影');

这产生的本身是一个数组,我相信它的,我不知道该怎么做一个循环列出所有例如电影标题

我怎么会得到所有电影的名字?

完整的脚本:

 < PHP/ *库文件纳入* /
    require_once('的lib / Facebook的/ FacebookSession.php');
    require_once('的lib / Facebook的/ FacebookRequest.php');
    require_once('的lib / Facebook的/ FacebookResponse.php');
    require_once('的lib / Facebook的/ FacebookSDKException.php');
    require_once('的lib / Facebook的/ FacebookRequestException.php');
    require_once('的lib / Facebook的/ FacebookRedirectLoginHelper.php');
    require_once('的lib / Facebook的/ FacebookAuthorizationException.php');
    require_once('的lib / Facebook的/ GraphObject.php');
    require_once('的lib / Facebook的/ GraphUser.php');
    require_once('的lib / Facebook的/ GraphSessionInfo.php');
    require_once('的lib / Facebook的/实体/ AccessToken.php');
    require_once('的lib / Facebook的/ HttpClients / FacebookCurl.php');
    require_once('的lib / Facebook的/ HttpClients / FacebookHttpable.php');
    require_once('的lib / Facebook的/ HttpClients / FacebookCurlHttpClient.php');/ *使用命名空间* /
    使用Facebook \\ FacebookSession;
    使用Facebook \\ FacebookRedirectLoginHelper;
    使用Facebook \\ FacebookRequest;
    使用Facebook \\ FacebookResponse;
    使用Facebook \\ FacebookSDKException;
    使用Facebook \\ FacebookRequestException;
    使用Facebook \\ FacebookAuthorizationException;
    使用Facebook \\ GraphObject;
    使用Facebook \\ GraphUser;
    使用Facebook \\ GraphSessionInfo;
    使用Facebook \\ FacebookHttpable;
    使用Facebook \\ FacebookCurlHttpClient;
    使用Facebook \\ FacebookCurl;/*处理*/    //1.Stat会议
        在session_start();    //2.Use应用程序ID,秘密的和重定向URL
        $ APP_ID ='0000000000000000';
        $ app_secret ='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
        $ REDIRECT_URL =HTTP://rafflebananza.com/Desktop/facebook.php';    //3.Initialize应用程序,创建辅助对象,并获得FB SESS
        FacebookSession :: setDefaultApplication($ APP_ID,$ app_secret);
        $帮手=新FacebookRedirectLoginHelper($ REDIRECT_URL);
        $ SESS = $ helper-> getSessionFromRedirect();    // 4。如果FB SESS存在回声名
        如果(使用isset($ SESS)){            //令牌存储在PHP会话
                $ _SESSION ['fb_token'] = $ sess->为gettoken();            //创建请求对象,执行和捕捉响应
                $ =请求新FacebookRequest($ SESS,GET,/我);            //从响应得到图形对象
                $响应= $请求 - >执行();
                $图表= $响应 - > getGraphObject(GraphUser ::类名());            //使用图形对象的方法来获取用户详细信息
                $ FB_id = $ graph->的getId();
                $ FB_First_Name = $ graph->的getProperty('FIRST_NAME');
                $ FB_Middle_Name = $ graph->的getProperty('middle_name');
                $ FB_Last_Name = $ graph->的getProperty('姓氏');
                $ FB_About_Bio = $ graph->的getProperty('生物');
                $ FB_image ='https://graph.facebook.com/'.$id.'/picture?width=300';
                $ FB_email = $ graph->的getProperty(电子邮件);                $ graphArray = $ graph-> asArray();
                $电影= $ graphArray ['电影'] ['数据'];
                的foreach($电影,电影$){
                    $名称= $电影['名'];
                }        //回声信息页:
            呼应'< H1>'$名字。'< / H1>';
            呼应。'<表>< TR>< TD><强>首先名称:< / STRONG>< / TD>< TD><输入类型=文本值='$ FB_First_Name 。'>< /输入>< / TD>< / TR>';
            回声< TR>< TD><强>中间名:< / STRONG>< / TD>< TD> $ FB_Middle_Name< / TD>< / TR>中;
            回声< TR>< TD><强>姓氏:其中; / STRONG>< / TD>< TD> $ FB_Last_Name< BR< / TD>< / TR>中;
            回声< TR>< TD><强>电子邮件地址:< / STRONG>< / TD>< TD> $ FB_email< / TD>< / TR>中;
            回声< TR>< TD><强>关于您:LT; / STRONG>< / TD>< TD> $ FB_About_Bio< / TD>< / TR>< /表>,
            回声< IMG SRC ='$ FB_形象/>< BR>< BR>中;        //注销按钮
            回声< A HREF =$注销。'><按钮和GT;注销< /按钮>< / A>中;
    }其他{
        //别的回声登录
            呼应'< A HREF ='$ helper-方式> getLoginUrl(阵列(电子邮件))。'>在Facebook和LT登录; / A>';
    }

更新

user9418问#2如何解析Facebook的图形API响应 bhushya回答有所见识的考虑应该怎么做。下面是我的最新进展,而previously我无论如何没有得到数据;

新的代码;

  $ USER_PROFILE =(新FacebookRequest(
    $ SESS,GET,/ ME /电影
)) - >执行() - GT; getGraphObject();
$电影= $ user_profile->的getProperty(数据);$ movies_data = $影片 - > asArray(); //这会做所有的工作对你..
的foreach($ movies_data为$行){
    后续代码var_dump($行);
}

结果:


  

对象(stdClass的)#28(4){[类别] =>串(5)电影[名称] =>
  串(19),博物馆惊魂夜[CREATED_TIME] =>串(24)
  2014-12-16T23:05:57 + 0000[ID] =>串(15)251922028320619}
  对象(stdClass的)排名第29(4){[类别] =>串(5)电影[名称] =>
  串(12),小尼基[CREATED_TIME] =>串(24)
  2014-12-14T02:35:10 + 0000[ID] =>串(15)112378985439799}
  对象(stdClass的)第30(4){[类别] =>串(5)电影[名称] =>
  串(26)回到未来三部曲[CREATED_TIME] =>串(24)
  2014-10-06T04:12:32 + 0000[ID] =>串(15)141545972523915}
  对象(stdClass的)#31(4){[类别] =>串(5)电影[名称] =>
  字符串(7)公驴[CREATED_TIME] =>串(24)
  2014-08-23T21:51:24 + 0000[ID] =>串(11)21295715752}
  对象(stdClass的)#32(4){[类别] =>串(5)电影[名称] =>
  串(25),布朗夫人的儿子们D'电影[CREATED_TIME] =>串(24)
  2014-08-06T10:16:10 + 0000[ID] =>串(15)217475368404328}
  对象(stdClass的)#33(4){[类别] =>串(5)电影[名称] =>
  串(10),马达加斯加[CREATED_TIME] =>串(24)
  2014-07-09T22:16:05 + 0000[ID] =>串(15)149800431712088}
  对象(stdClass的)#34(4){[类别] =>串(5)电影[名称] =>
  字符串(6)冻结[CREATED_TIME] =>串(24)
  2014-05-27T20:47:31 + 0000[ID] =>串(15)482368755113431}
  对象(stdClass的)#35(4){[类别] =>串(5)电影[名称] =>
  字符串(9)玩具总动员[CREATED_TIME] =>串(24)
  2014-04-15T01:39:17 + 0000[ID] =>串(11)10498014129}
  对象(stdClass的)#36(4){[类别] =>串(5)电影[名称] =>
  串(19)摆脱了电影[CREATED_TIME] =>串(24)
  2014-02-20T14:16:06 + 0000[ID] =>串(15)135991503231501}
  对象(stdClass的)#37(4){[类别] =>串(5)电影[名称] =>
  串(13),狮子王[CREATED_TIME] =>串(24)
  2014-02-19T08:32:34 + 0000[ID] =>串(11)12393266550}
  对象(stdClass的)#38(4){[类别] =>串(5)电影[名称] =>
  串(13)卑鄙的我[CREATED_TIME] =>串(24)
  2014-02-19T08:32:29 + 0000[ID] =>串(15)117067844993952}
  对象(stdClass的)排名第39(4){[类别] =>串(5)电影[名称] =>
  串(4)雷神[CREATED_TIME] =>串(24)
  2013-11-29T02:22:14 + 0000[ID] =>串(15)113589202010624}
  对象(stdClass的)#40(4){[类别] =>串(5)电影[名称] =>
  串(21)史酷比:电影[CREATED_TIME] =>串(24)
  2013-10-17T13:41:51 + 0000[ID] =>串(15)306089742863765}
  对象(stdClass的)#41(4){[类别] =>串(5)电影[名称] =>
  串(30)汉塞尔和放大器;格蕾特:女巫猎人[CREATED_TIME] =>
  串(24)2013-10-15T21:22:05 + 0000[ID] =>串(15)
  271965656164363}对象(stdClass的)#42(4){[类别] =>串(5)
  电影[名称] =>串(12),哈利·波特[CREATED_TIME] =>
  串(24)2013-10-09T21:29:08 + 0000[ID] =>串(12)
  156794164312}对象(stdClass的)#43(4){[类别] =>串(5)
  电影[名称] =>字符串(9)星球大战[CREATED_TIME] =>串(24)
  2013-08-30T20:12:14 + 0000[ID] =>串(15)216676368377759}
  对象(stdClass的)排名第44(4){[类别] =>串(5)电影[名称] =>
  字符串(6)马仔[CREATED_TIME] =>串(24)
  2013-07-22T12:25:27 + 0000[ID] =>串(15)136787429687873}
  对象(stdClass的)#45(4){[类别] =>串(5)电影[名称] =>
  串(21),博物馆奇妙夜2[CREATED_TIME] =>串(24)
  2013-06-14T01:18:02 + 0000[ID] =>串(15)115126478502712}
  对象(stdClass的)#46(4){[类别] =>串(5)电影[名称] =>
  串(30)圣诞夜惊魂[CREATED_TIME] =>
  串(24)2013-06-08T11:11:36 + 0000[ID] =>串(15)
  173587329354820}对象(stdClass的)#47(4){[类别] =>串(5)
  电影[名称] =>串(11)环太平洋[CREATED_TIME] =>
  串(24)2013-05-16T19:30:24 + 0000[ID] =>串(15)
  439835889373123}对象(stdClass的)#48(4){[类别] =>串(5)
  电影[名称] =>串(11)湮灭英国[CREATED_TIME] =>
  串(24)2013-02-14T23:02:31 + 0000[ID] =>串(15)
  235958443193536}对象(stdClass的)#49(4){[类别] =>串(5)
  电影[名称] =>串(5)怪物史莱克[CREATED_TIME] =>串(24)
  2012-10-03T07:01:57 + 0000[ID] =>串(12)355374000182}
  对象(stdClass的)#50(4){[类别] =>串(5)电影[名称] =>
  串(21)史酷比:电影[CREATED_TIME] =>串(24)
  2012-09-20T11:55:28 + 0000[ID] =>串(15)106352129401640}
  对象(stdClass的)#51(4){[类别] =>串(5)电影[名称] =>
  串(14)德古拉不为人知的[CREATED_TIME] =>串(24)
  2012-09-17T16:15:38 + 0000[ID] =>串(15)332230740134829}
  对象(stdClass的)#52(4){[类别] =>串(15)电影人物
  [名称] =>串(5)辛巴[CREATED_TIME] =>串(24)
  2012-09-06T22:23:22 + 0000[ID] =>串(11)27665751322}


我的全code现在是这个上面我呼应页面实现了相同的。我现在需要学习如何通过循环和列表中的每个电影环绕每一个在标签!只是名称


解决方案

解决段

  $ FB_User_Interests_Movies =(新FacebookRequest(
    $ SESS,GET,/ ME /电影
)) - >执行() - GT; getGraphObject() - GT; asArray();
的foreach($ FB_User_Interests_Movies ['数据']为$键){
    回声$键盘>的名字。'< BR />';
}

如何解决

很多事情是Facebook的图形API都在这,所以我扩大研究,以询问如何获取用户的朋友和诸如此类的东西。这使我一个YouTube视频名为 Facebook的PHP SDK V4:获取网页的名单由用户喜欢|零件这足以10 来解释如何实现我的问题!

My Array;

{
  "bio": "Testing Facebook Bio -> Stupidly forgot to set whilst trying to fetch this information testing my latest Facebook App!", 
  "movies": {
    "data": [
      {
        "name": "Night At The Museum", 
        "id": "251922028320619"
      }, 
      {
        "name": "Little Nicky", 
        "id": "112378985439799"
      }, 
      {
        "genre": "Action / Adventure / Comedy / Family / Sci-Fi", 
        "name": "Back to the Future Trilogy", 
        "id": "141545972523915"
      }, 
      {
        "genre": "Stupid", 
        "name": "Jackass", 
        "id": "21295715752"
      }, 
      {
        "genre": "Comedy", 
        "name": "Mrs. Brown's Boys D'Movie", 
        "id": "217475368404328"
      }, 
      {
        "genre": "Animation, Family", 
        "name": "Madagascar", 
        "id": "149800431712088"
      }, 
      {
        "genre": "Animation", 
        "name": "Frozen", 
        "id": "482368755113431"
      }, 
      {
        "genre": "Animation", 
        "name": "Toy Story", 
        "id": "10498014129"
      }, 
      {
        "genre": "This is a gritty drama that develops into an uplifting story of triumph over adversity. It should appeal to a wide audience,  both male and female.", 
        "name": "Breaking Free  Film", 
        "id": "135991503231501"
      }, 
      {
        "genre": "Animation", 
        "name": "The Lion King", 
        "id": "12393266550"
      }, 
      {
        "genre": "Animation | Comedy | Family ", 
        "name": "Despicable Me", 
        "id": "117067844993952"
      }, 
      {
        "genre": "Action / Adventure", 
        "name": "Thor", 
        "id": "113589202010624"
      }, 
      {
        "name": "Scooby-Doo: The Movie", 
        "id": "306089742863765"
      }, 
      {
        "genre": "Action / fairy tale", 
        "name": "Hansel & Gretel: Witch Hunters", 
        "id": "271965656164363"
      }, 
      {
        "name": "Harry Potter", 
        "id": "156794164312"
      }, 
      {
        "name": "Star Wars", 
        "id": "216676368377759"
      }, 
      {
        "name": "Minion", 
        "id": "136787429687873"
      }, 
      {
        "name": "Night at the Museum 2", 
        "id": "115126478502712"
      }, 
      {
        "genre": "Animation, Holiday, Family", 
        "name": "The Nightmare Before Christmas", 
        "id": "173587329354820"
      }, 
      {
        "name": "Pacific Rim", 
        "id": "439835889373123"
      }, 
      {
        "genre": "Action Adventure", 
        "name": "Oblivion UK", 
        "id": "235958443193536"
      }, 
      {
        "genre": "Animation, Family", 
        "name": "Shrek", 
        "id": "355374000182"
      }, 
      {
        "name": "Scooby Doo: The Movie", 
        "id": "106352129401640"
      }, 
      {
        "genre": "Epic Action-Adventure", 
        "name": "Dracula Untold", 
        "id": "332230740134829"
      }, 
      {
        "name": "Simba", 
        "id": "27665751322"
      }
    ], 
    "paging": {
      "next": "https://graph.facebook.com/v2.2/663878750359892/movies?fields=genre,name&limit=25&offset=25&__after_id=enc_AezyAtvaN1UtcaRwF9kgU5Z5PIv07LU_3Wli-CRCkYEol9BoJJtn86fNGT4v-XsnG-o"
    }
  }, 
  "id": "663878750359892"
}

I know to get the "Bio" from my array, however this is pretty much out there onthe internet how to get the first level information from the Facebook API Array passed on;

$FB_About_Bio = $graph->getProperty('bio');

However when it comes to calling for "movies";

$FB_About_Movies = $graph->getProperty('movies');

This produces an array of itself I believe of which I do not know how to do a loop to list all the movie titles for example

How would I get all the movie names?

Full Script:

<?php

/* INCLUSION OF LIBRARY FILEs*/
    require_once( 'lib/Facebook/FacebookSession.php');
    require_once( 'lib/Facebook/FacebookRequest.php' );
    require_once( 'lib/Facebook/FacebookResponse.php' );
    require_once( 'lib/Facebook/FacebookSDKException.php' );
    require_once( 'lib/Facebook/FacebookRequestException.php' );
    require_once( 'lib/Facebook/FacebookRedirectLoginHelper.php');
    require_once( 'lib/Facebook/FacebookAuthorizationException.php' );
    require_once( 'lib/Facebook/GraphObject.php' );
    require_once( 'lib/Facebook/GraphUser.php' );
    require_once( 'lib/Facebook/GraphSessionInfo.php' );
    require_once( 'lib/Facebook/Entities/AccessToken.php');
    require_once( 'lib/Facebook/HttpClients/FacebookCurl.php' );
    require_once( 'lib/Facebook/HttpClients/FacebookHttpable.php');
    require_once( 'lib/Facebook/HttpClients/FacebookCurlHttpClient.php');

/* USE NAMESPACES */
    use Facebook\FacebookSession;
    use Facebook\FacebookRedirectLoginHelper;
    use Facebook\FacebookRequest;
    use Facebook\FacebookResponse;
    use Facebook\FacebookSDKException;
    use Facebook\FacebookRequestException;
    use Facebook\FacebookAuthorizationException;
    use Facebook\GraphObject;
    use Facebook\GraphUser;
    use Facebook\GraphSessionInfo;
    use Facebook\FacebookHttpable;
    use Facebook\FacebookCurlHttpClient;
    use Facebook\FacebookCurl;

/*PROCESS*/

    //1.Stat Session
        session_start();

    //2.Use app id,secret and redirect url
        $app_id = '000000000000000';
        $app_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
        $redirect_url='http://rafflebananza.com/Desktop/facebook.php';

    //3.Initialize application, create helper object and get fb sess
        FacebookSession::setDefaultApplication($app_id,$app_secret);
        $helper = new FacebookRedirectLoginHelper($redirect_url);
        $sess = $helper->getSessionFromRedirect();

    //4. if fb sess exists echo name 
        if(isset($sess)){

            //store the token in the php session
                $_SESSION['fb_token']=$sess->getToken();

            //create request object,execute and capture response
                $request = new FacebookRequest($sess,'GET','/me');

            // from response get graph object
                $response = $request->execute();
                $graph = $response->getGraphObject(GraphUser::classname());

            // use graph object methods to get user details
                $FB_id = $graph->getId();
                $FB_First_Name = $graph->getProperty('first_name');
                $FB_Middle_Name = $graph->getProperty('middle_name');
                $FB_Last_Name = $graph->getProperty('last_name');
                $FB_About_Bio = $graph->getProperty('bio');
                $FB_image = 'https://graph.facebook.com/'.$id.'/picture?width=300';
                $FB_email = $graph->getProperty('email');

                $graphArray = $graph->asArray();
                $movies = $graphArray['movies']['data'];
                foreach ($movies as $movie) {
                    $name = $movie['name'];
                }

        // Echo Info To Page:
            echo '<h1>'.$name.'</h1>';
            echo '<table><tr><td><strong>First Name:</strong></td><td><input type="text" value="'.$FB_First_Name.'"></input></td></tr>';
            echo "<tr><td><strong>Middle Name: </strong></td><td>$FB_Middle_Name</td></tr>";
            echo "<tr><td><strong>Last Name: </strong></td><td>$FB_Last_Name <br</td></tr>";
            echo "<tr><td><strong>E-Mail Address:</strong></td><td>$FB_email</td></tr>";
            echo "<tr><td><strong>About You:</strong></td><td>$FB_About_Bio</td></tr></table>";
            echo "<img src='FB_$image' /><br><br>";

        // Logout Button
            echo "<a href='".$logout."'><button>Logout</button></a>";


    }else{
        //else echo login
            echo '<a href="'.$helper->getLoginUrl(array('email')).'" >Login with facebook</a>';
    }

Update

user9418 asked on Stackoverflow "How to parse a facebook graph api response" and bhushya answer has given somewhat of an insight to how it should be done. Below is my latest progress whereas previously I was getting no data whatsoever;

New Snippet;

$user_profile = (new FacebookRequest(
    $sess, 'GET', '/me/movies'
))->execute()->getGraphObject();
$movies =  $user_profile->getProperty('data');

$movies_data = $movies->asArray();//this will do all job for you..
foreach($movies_data as $row){
    var_dump($row);
}

Result:

object(stdClass)#28 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(19) "Night At The Museum" ["created_time"]=> string(24) "2014-12-16T23:05:57+0000" ["id"]=> string(15) "251922028320619" } object(stdClass)#29 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(12) "Little Nicky" ["created_time"]=> string(24) "2014-12-14T02:35:10+0000" ["id"]=> string(15) "112378985439799" } object(stdClass)#30 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(26) "Back to the Future Trilogy" ["created_time"]=> string(24) "2014-10-06T04:12:32+0000" ["id"]=> string(15) "141545972523915" } object(stdClass)#31 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(7) "Jackass" ["created_time"]=> string(24) "2014-08-23T21:51:24+0000" ["id"]=> string(11) "21295715752" } object(stdClass)#32 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(25) "Mrs. Brown's Boys D'Movie" ["created_time"]=> string(24) "2014-08-06T10:16:10+0000" ["id"]=> string(15) "217475368404328" } object(stdClass)#33 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(10) "Madagascar" ["created_time"]=> string(24) "2014-07-09T22:16:05+0000" ["id"]=> string(15) "149800431712088" } object(stdClass)#34 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(6) "Frozen" ["created_time"]=> string(24) "2014-05-27T20:47:31+0000" ["id"]=> string(15) "482368755113431" } object(stdClass)#35 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(9) "Toy Story" ["created_time"]=> string(24) "2014-04-15T01:39:17+0000" ["id"]=> string(11) "10498014129" } object(stdClass)#36 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(19) "Breaking Free Film" ["created_time"]=> string(24) "2014-02-20T14:16:06+0000" ["id"]=> string(15) "135991503231501" } object(stdClass)#37 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(13) "The Lion King" ["created_time"]=> string(24) "2014-02-19T08:32:34+0000" ["id"]=> string(11) "12393266550" } object(stdClass)#38 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(13) "Despicable Me" ["created_time"]=> string(24) "2014-02-19T08:32:29+0000" ["id"]=> string(15) "117067844993952" } object(stdClass)#39 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(4) "Thor" ["created_time"]=> string(24) "2013-11-29T02:22:14+0000" ["id"]=> string(15) "113589202010624" } object(stdClass)#40 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(21) "Scooby-Doo: The Movie" ["created_time"]=> string(24) "2013-10-17T13:41:51+0000" ["id"]=> string(15) "306089742863765" } object(stdClass)#41 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(30) "Hansel & Gretel: Witch Hunters" ["created_time"]=> string(24) "2013-10-15T21:22:05+0000" ["id"]=> string(15) "271965656164363" } object(stdClass)#42 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(12) "Harry Potter" ["created_time"]=> string(24) "2013-10-09T21:29:08+0000" ["id"]=> string(12) "156794164312" } object(stdClass)#43 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(9) "Star Wars" ["created_time"]=> string(24) "2013-08-30T20:12:14+0000" ["id"]=> string(15) "216676368377759" } object(stdClass)#44 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(6) "Minion" ["created_time"]=> string(24) "2013-07-22T12:25:27+0000" ["id"]=> string(15) "136787429687873" } object(stdClass)#45 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(21) "Night at the Museum 2" ["created_time"]=> string(24) "2013-06-14T01:18:02+0000" ["id"]=> string(15) "115126478502712" } object(stdClass)#46 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(30) "The Nightmare Before Christmas" ["created_time"]=> string(24) "2013-06-08T11:11:36+0000" ["id"]=> string(15) "173587329354820" } object(stdClass)#47 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(11) "Pacific Rim" ["created_time"]=> string(24) "2013-05-16T19:30:24+0000" ["id"]=> string(15) "439835889373123" } object(stdClass)#48 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(11) "Oblivion UK" ["created_time"]=> string(24) "2013-02-14T23:02:31+0000" ["id"]=> string(15) "235958443193536" } object(stdClass)#49 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(5) "Shrek" ["created_time"]=> string(24) "2012-10-03T07:01:57+0000" ["id"]=> string(12) "355374000182" } object(stdClass)#50 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(21) "Scooby Doo: The Movie" ["created_time"]=> string(24) "2012-09-20T11:55:28+0000" ["id"]=> string(15) "106352129401640" } object(stdClass)#51 (4) { ["category"]=> string(5) "Movie" ["name"]=> string(14) "Dracula Untold" ["created_time"]=> string(24) "2012-09-17T16:15:38+0000" ["id"]=> string(15) "332230740134829" } object(stdClass)#52 (4) { ["category"]=> string(15) "Movie character" ["name"]=> string(5) "Simba" ["created_time"]=> string(24) "2012-09-06T22:23:22+0000" ["id"]=> string(11) "27665751322" }

My full code now being the same with this implemented above my echoing to the page. I just need to learn now how to loop through and list only the name of each movie wrapping each one in a tag!

解决方案

Resolved Snippet

$FB_User_Interests_Movies = (new FacebookRequest(
    $sess, 'GET', '/me/movies'
))->execute()->getGraphObject()->asArray();
foreach($FB_User_Interests_Movies['data'] as $key) {
    echo $key->name.'<br />';
}

How I resolved

Many things are in the Facebook Graph API alike this so I expanded research to ask how to get user friends and whatnot. This lead me to a YouTube video titled "Facebook PHP SDK v4: Get List of Pages Liked by User | Part 10" which was enough to explain how to achieve my question!

这篇关于解析Facebook的PHP API响应 - 修复版/回收2015年5月2日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆