I know this question asked server times, but I could not find a solution from other posts:
My goal is to read the facebook feed from one of my facebook sites! There are several posts with several photos on this site.
In the first call that you see, I always get only one photo, but I need all of them. To do this, I make a secound request, which should give me all the information for this message if I use v2.1, which I modify in FacebookRequest.php
Here is my code:
FacebookSession::setDefaultApplication('yyy','xxxxx'); $session = new FacebookSession('yyy|xxxxx'); $url = '/{pageid}/feed'; $request = new FacebookRequest($session, 'GET', $url); $response = $request->execute(); graphObject = $response->getGraphObject(); $rawFeed = $graphObject->asArray(); foreach($rawFeed['data'] as $item) { $x = explode('_',$item->id); $url = "/".$x[0]; $request = new FacebookRequest($session, 'GET', $url); $response = $request->execute(); $graphObject = $response->getGraphObject(); $object = $graphObject->asArray(); echo "<pre>";var_dump($object);echo "<pre>"; }
If I use this code, I always get an error:
Fatal error: Uncaught exception 'Facebook\FacebookAuthorizationException' with message '(#100) Requires user session'
Why does the first query return data back, and scound is an exception!
Change 1
Found a solution to the session problem ( Facebook token for pages ) - (top answer), but still a problem with the photo:
Now I am returning data from Facebook, but I do not receive attached photos to the message!
This is how I no longer get authentication issues
$accessToken = "{accestToken from GRAPH API EXPLORER}"; $session = new FacebookSession($accessToken); $url = "/{myPersonalFB-ID}/accounts"; $request = new FacebookRequest($session, 'GET', $url); $response = $request->execute(); $graphObject = $response->getGraphObject(); $pages = $graphObject->asArray(); $pageAccesstoken = false; foreach($pages['data'] as $page) { if($page->id != "{MyPageID}") continue; else { $pageAccesstoken = $page->access_token; } } $session = new FacebookSession($pageAccesstoken); $url = '/{MyPageID}/feed'; ... ...