I am trying to parse the facebook graph object and allow the view to iterate through the objects and its array. However, I am hitting a roadblock and the view is showing blank.
facebook library:
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;
}
}
controller:
$data['facebook'] = $this->facebook->get_user_profile("coach");
$this->load->template('default_template', $data);
view:
foreach($facebook as $fb_item) {
echo var_dump($fb_item);
echo var_dump($facebook);
}
But what I really want to do is:
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;
the object that is returned when doing a print_r:
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
)
)
Any tips or direction on how to proceed?