1

I know this question has been ask serveral times but i'm not able to find a solution from the other posts:

My goal is to read a facebook feed from one of mine facebook sites! On that site there are several posts with multiple photos.

In the first call you see down, I always get only one photo, but i need all of them. For that i make the secound Request which should deliver me all details for that post if i use v2.1 which i have changend in FacebookRequest.php

Here 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 the error:

Fatal error: Uncaught exception 'Facebook\FacebookAuthorizationException' with message '(#100) Requires user session'

Why does the first request returns back the data and the scound one runs into this exception!

Edit 1

Found a solution for the session problem(Facebook Access Token for Pages) - ( top answer ) but still stuck at the photo problem:

Now i get back the data from Facebook, but i don't get the photos attached to the post!

Here the way i get no authentication problem anymore

$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';
...
...
Community
  • 1
  • 1
  • Please show how you implemented it using the page access token now (especially where you set it to be used for the requests). If your first call succeeds with page access token, there is no obvious reason why reading the data of the individual posts shouldn’t. Btw., you should look into making “nested requests” as described in the docs, so that you have to do only one request, instead of multiple requests in a loop. – CBroe Sep 03 '14 at 09:09
  • See changes in Edit 1: i get back the pageAccestoken from my accounts for this page. But in the request /v2.1/{post-id} i don't get back any photo, but there are more than one in each of the posts! i also tried allready to add ?fields=attachments with the effect that i get an error telling me there are no attachments! – Thomas Schober Sep 09 '14 at 12:58

2 Answers2

0

If you require an app session, use the following instead:

$session = FacebookSession::newAppSession();

You can then pass this app session into your API call to retrieve the page feed.

Niraj Shah
  • 15,087
  • 3
  • 41
  • 60
0

It seems it's a Facebook bug. My colleague opened an issue. Here's the link: https://developers.facebook.com/bugs/762280800482269/ You also can find some info here: https://developers.facebook.com/bugs/790976317600139/ Hope it will help you.

Eridana
  • 2,418
  • 23
  • 26