解析Facebook PHP API响应 - 修复/回收05/02/2015 [英] Parsing Facebook PHP API Response - Remastered / Recycled 05/02/2015

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

问题描述

我的数组;

  {
bio - >
电影:{
数据:[
{
名称,愚蠢地忘记设置,尝试获取此信息测试我的最新的Facebook应用程序! :博物馆之夜,
id:251922028320619
},
{
name:Little Nicky,
id :112378985439799
},
{
类型:动作/冒险/喜剧/家庭/科幻,
名称:返回未来三部曲,
id:141545972523915
},
{
类型:愚蠢,
name:Jackass
id:21295715752
},
{
流派:喜剧,
名称:布朗夫人的男孩电影,
id:217475368404328
},
{
类型:动画,家庭,
名称:马dagascar,
id:149800431712088
},
{
流派:动画,
名称:冻结 b $ bid:482368755113431
},
{
流派:动画,
名称:玩具总动员,
id:10498014129
},
{
流派:这是一个精湛的戏剧,发展成为胜利胜利的令人振奋的故事。 b $ bbbbb

id:

{
genre:动画,
名称:狮子王,
id:12393266550
},
{
流派:动画|喜剧|家庭,
名字:卑鄙的我,
id:117067844993952
},
{
类型:动作/冒险,
name:Thor,
id:113589202010624
},
{
name:Scooby-Doo:电影,
id:306089742863765
},
{
类型:动作/童话,
name:Hansel &安培; Gretel:Witch Hunters,
id:271965656164363
},
{
name:Harry Potter,
id 156794164312
},
{
name:星球大战,
id:216676368377759
},
{
name:Minion,
id:136787429687873
},
{
name:博物馆2夜,
id:115126478502712
},
{
类型:动画,度假,家庭,
名称:圣诞节前的噩梦 ,
id:173587329354820
},
{
name:Pacific Rim,
id:439835889373123
$,
{
类型:行动冒险,
名称:湮灭英国,
id:235958443193536
} ,
{
流派:动画,家庭,
名称:史瑞克,
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
}

我知道要从我的阵列中获取Bio,但是这在互联网上几乎是如此得到Facebook API Array传出的第一级信息;

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

然而,当涉及到电影;

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

这产生一个本身的数组我相信我不知道如何做一个循环列表所有电影标题例如



如何获取所有电影名称?



完整脚本:

 <?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 / Entities / AccessToken.php');
require_once('lib / Facebook / HttpClients / FacebookCurl.php');
require_once('lib / Facebook / HttpClients / FacebookHttpable.php');
require_once('lib / Facebook / HttpClients / FacebookCurlHttpClient.php');

/ *使用NAMESPACES * /
使用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;

/ * 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。如果fb sess存在echo name
if(isset($ sess)){

//将令牌存储在php会话中
$ _SESSION ['fb_token'] = $ sess - >为gettoken();

//创建请求对象,执行和捕获响应
$ request = new FacebookRequest($ sess,'GET','/ me');

//从响应获取图形对象
$ response = $ request-> execute();
$ graph = $ response-> getGraphObject(GraphUser :: classname());

//使用图形对象方法获取用户详细信息
$ 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'< h1>'。$ name。'< / h1>';
echo'< table>< tr>< td>< strong>名字:< / strong>< / td>< td>< input type =textvalue = $ FB_First_Name。 '>< /输入>< / TD>< / TR>';
echo< tr>< td>< strong>中间名称:< / strong>< / td>< td> $ FB_Middle_Name< / td>< / tr>
echo< tr>< td>< strong>姓:< / strong>< / td>< td> $ FB_Last_Name< br< / td>< / tr> ;
echo< tr>< td>< strong>电子邮件地址:< / strong>< / td>< td> $ FB_email< / td>< / tr>
echo< tr>< td>< strong>关于你:< / strong>< / td>< td> $ FB_About_Bio< / td>< / tr>< / table> ;;
echo< img src ='FB_ $ image'/>< br>< br>;

//注销按钮
echo< a href ='$ logout。'>< button>注销< / button>< / a>;


} else {
// else echo login
echo'< a href ='$ helper-> getLoginUrl(array('email' ))。'>使用脸书登录< / a>';
}



更新



user9418询问Stackoverflow如何解析Facebook图表api响应 bhushya answer 已经对如何做到这一点有所了解。以下是我最新的进展,而以前我没有收到任何数据;



新的代码段




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

$ movies_data = $ movies-> asArray(); //这将为你做所有的工作..
foreach($ movies_data as $ row){
var_dump $行);
}

结果:


object(stdClass)#28(4){[category] => string(5)Movie[name] =>
string(19)博物馆之夜[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)回到未来三部曲[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){[c ategory] => string(5)Movie[name] =>
string(25)布朗的男孩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 ){[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)打破免费电影[created_time] => string(24)
2014-02-20T14:16:06 + 0000[id] => string(15)135991503231501}
object(stdClass)#3 7(4){[category] => string(5)Movie[name] =>
string(13)狮子王[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 [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 )$ 30 $
对象(stdClass)#41(4){[category] => string(5)Movie[name] =>
string(30) &安培; 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 ){[category] => string(5)
Movie[name] => string(9)星球大战[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: 0000[id] => string(15)136787429687873}
object(stdClass)#45(4){[category] => string(5)Movie[name] =>
string(21)博物馆之夜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)圣诞节之前的梦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) 05-16T19:30:24 + 0000[id] => string(15)
439835889373123} object(stdClass)#48(4){[category] => string
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) o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o :电影[created_time] => string(24)
2012 -09-20T11:55:28 + 0000[id] => string(15)106352129401640}
object(stdClass)#51(4){[category] => string )Movie[name] =>
string(14)Dracula Untold[created_time] => string(24)
2012-09-17T16:15:38 + 0000 [id] => string(15)332230740134829}
对象(stdClass)#52(4){[category] => string(15)电影字符
[ name] => string(5)Simba[created_time] => string(24)
2012-09-06T22:23:22 + 0000[id] => string 11)27665751322}


我的完整代码现在与我在回页面上实现的一样。我只需要学习如何循环并列出每个包装每个电影的标签的名称!

解决方案

已解决的片段



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



我如何解决



许多事情都在Facebook Graph 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响应 - 修复/回收05/02/2015的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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