Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何解析facebook图形对象并在视图中迭代?_Php_Facebook_Codeigniter_Facebook Graph Api - Fatal编程技术网

Php 如何解析facebook图形对象并在视图中迭代?

Php 如何解析facebook图形对象并在视图中迭代?,php,facebook,codeigniter,facebook-graph-api,Php,Facebook,Codeigniter,Facebook Graph Api,我试图解析facebook graph对象,并允许视图遍历对象及其数组。然而,我遇到了一个路障,视图显示为空白 facebook图书馆: require_once('Facebook/autoload.php'); use Facebook\FacebookSession; use Facebook\FacebookRequest; use Facebook\GraphUser; use Facebook\FacebookRequestException; use Facebook\Faceb

我试图解析facebook graph对象,并允许视图遍历对象及其数组。然而,我遇到了一个路障,视图显示为空白

facebook图书馆:

require_once('Facebook/autoload.php');

use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
use Facebook\FacebookRedirectLoginHelper;

class Facebook {
  protected $ci;

  public function __construct() {
    $this->ci =& get_instance();
    $this->ci->load->library('session');
    if(!isset($_SESSION)) {
      session_start();
    }
    FacebookSession::setDefaultApplication($this->ci->config->item('api_id', 'facebook'), $this->ci->config->item('app_secret', 'facebook'));
    $this->session = new FacebookSession($this->ci->config->item('app_token', 'facebook'));
  }

  public function get_user_profile($user) {
    $request = (new FacebookRequest($this->session, 'GET', '/' . $user))->execute()->getGraphObject(GraphUser::className());

    return $request;
  }
}
控制器:

$data['facebook'] = $this->facebook->get_user_profile("coach");
$this->load->template('default_template', $data);
视图:

但我真正想做的是:

echo $fb_item->name; //to return name if its singular
echo $fb_item->cover->id; //for the multi dimensional objects
echo $fb_item->cover->source;
执行打印时返回的对象:

Facebook\GraphObject Object
(
    [backingData:protected] => Array
        (
            [id] => 24902886692
            [about] => The official page of Coach, a modern American luxury brand with a rich heritage of craftsmanship and New York style. Contact us at: http://bit.ly/1fdsZtA.
            [can_post] => 
            [category] => Retail and consumer merchandise
            [checkins] => 0
            [company_overview] => Coach is a modern American luxury brand with a rich heritage rooted in quality and craftsmanship. All over the world, the Coach name is synonymous with the ease and sophistication of New York style.
            [cover] => stdClass Object
                (
                    [cover_id] => 10152666534996693
                    [offset_x] => 0
                    [offset_y] => 0
                    [source] => https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xfp1/v/t1.0-9/s720x720/10408485_10152666534996693_825399149096092916_n.jpg?oh=bb278cd2e136b99d5fb1a0823ff51f4d&oe=5591EAA7&__gda__=1431366774_f1edfc44f1a0e9ba2e83f491a21295ce
                    [id] => 10152666534996693
                )

            [description] => * * * * * * * * * *
Coach Facebook Fan Page Policy
We encourage open conversation on the Coach Facebook fan page. However, Coach reserves the right to delete any posts or images that we, in our sole discretion, deem inappropriate.
            [founded] => 1941
            [has_added_app] => 
            [is_community_page] => 
            [is_published] => 1
            [likes] => 5850158
            [link] => https://www.facebook.com/coach
            [location] => stdClass Object
                (
                    [city] => New York
                    [country] => United States
                    [state] => NY
                )

            [name] => Coach
            [parking] => stdClass Object
                (
                    [lot] => 0
                    [street] => 0
                    [valet] => 0
                )

            [talking_about_count] => 60665
            [username] => coach
            [website] => www.coach.com www.facebook.com/coach www.twitter.com/coach www.youtube.com/coach http://www.pinterest.com/coach/ http://instagram.com/Coach/
            [were_here_count] => 0
        )

)

有关于如何进行的提示或指导吗?

好的,我能够找到解决方案。 以数组形式返回对象:

getGraphObject->AsArray

然后可以通过视图进行迭代

Facebook\GraphObject Object
(
    [backingData:protected] => Array
        (
            [id] => 24902886692
            [about] => The official page of Coach, a modern American luxury brand with a rich heritage of craftsmanship and New York style. Contact us at: http://bit.ly/1fdsZtA.
            [can_post] => 
            [category] => Retail and consumer merchandise
            [checkins] => 0
            [company_overview] => Coach is a modern American luxury brand with a rich heritage rooted in quality and craftsmanship. All over the world, the Coach name is synonymous with the ease and sophistication of New York style.
            [cover] => stdClass Object
                (
                    [cover_id] => 10152666534996693
                    [offset_x] => 0
                    [offset_y] => 0
                    [source] => https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xfp1/v/t1.0-9/s720x720/10408485_10152666534996693_825399149096092916_n.jpg?oh=bb278cd2e136b99d5fb1a0823ff51f4d&oe=5591EAA7&__gda__=1431366774_f1edfc44f1a0e9ba2e83f491a21295ce
                    [id] => 10152666534996693
                )

            [description] => * * * * * * * * * *
Coach Facebook Fan Page Policy
We encourage open conversation on the Coach Facebook fan page. However, Coach reserves the right to delete any posts or images that we, in our sole discretion, deem inappropriate.
            [founded] => 1941
            [has_added_app] => 
            [is_community_page] => 
            [is_published] => 1
            [likes] => 5850158
            [link] => https://www.facebook.com/coach
            [location] => stdClass Object
                (
                    [city] => New York
                    [country] => United States
                    [state] => NY
                )

            [name] => Coach
            [parking] => stdClass Object
                (
                    [lot] => 0
                    [street] => 0
                    [valet] => 0
                )

            [talking_about_count] => 60665
            [username] => coach
            [website] => www.coach.com www.facebook.com/coach www.twitter.com/coach www.youtube.com/coach http://www.pinterest.com/coach/ http://instagram.com/Coach/
            [were_here_count] => 0
        )

)