0

I want read the friendlist of a facebook user with fb sdk 4, but the result is always empty. I created the application on facebook for the id and key and the friendlist permission should be granted by default.

The login and retrieving profiledata works, but not the friendlist request. Here the code:

FacebookSession::setDefaultApplication($id, $key);
try {
    $session = $helper->getSessionFromRedirect();
} catch(Exception $ex) { /* handle error */ }

$request = new FacebookRequest($session, 'GET', '/me/friends');
$response = $request->execute();
$graphObject = $response->getGraphObject();

print_r($graphObject);

Instead of '/me/friends' I also tried '/{fbid}/friends', '/{fbid}/taggable_friends' and some other combinations I found with google, but all with the same result.

What did I wrong? And I also want to read the list if the user is offline once an hour. Is that possible and how?

Daniel
  • 539
  • 4
  • 25

1 Answers1

2

It is completely unrelated to the PHP SDK, since v2.0 of the Graph API you can only get friends who authorized your App with user_friends too. This has been discussed in countless threads already, here´s one with a very detailed answer: Get ALL User Friends Using Facebook Graph API - Android

If you want to read stuff while the user is offline, you need to store his User Access Token and use it for an API call. Make sure you extend it though, or it will only be valid for 2 hours.

More information about Access Tokens:

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • I found that page and tried that suggestions, but it does not help. EDIT: So, once a token is invalid, I cannot get a new one? – Daniel Jul 06 '15 at 11:24
  • of course you can get a new one, but not automatically. the user has to use your app if you want to refresh it. – andyrandy Jul 06 '15 at 11:48