0

My code:

$fb = new Facebook\Facebook([
    'app_id'=>$clientId, 
    'app_secret'=>$clientSecret, 
    'default_graph_version' => 'v2.9',
    ]);
$uid = 'my_uid';
try {
  $response = $fb->get('/'.$uid.'/posts', $clientId.'|'.$clientSecret);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo $e->getMessage();
  exit;
}

var_dump($response->getDecodedBody());

$uid is ID of my own facebook page, there is have the posts. App domain in the settings is localhost, site URL http://localhost/FB.

Output of var_dump:

object(stdClass)[10] public 'data' => array (size=0) empty

evgeny_s
  • 391
  • 1
  • 6
  • 17
  • Where is the part where the user grants your app the necessary permission to read their posts? – CBroe Jun 13 '17 at 08:08
  • How can I ask the user for permission to `user_posts`? – evgeny_s Jun 13 '17 at 08:43
  • https://developers.facebook.com/docs/facebook-login/permissions/requesting-and-revoking, https://developers.facebook.com/docs/php/howto/example_facebook_login – CBroe Jun 13 '17 at 09:01
  • first get the access_token which will contain the required permissions that will allow you to read posts, then pass that access_token while calling that api. – Rahul Sharma Jun 13 '17 at 09:44
  • It turns out that I need to get posts from a public page. This was simpler: https://stackoverflow.com/questions/26660728/embed-activity-feed-of-a-public-facebook-page-without-forcing-user-to-login-allo – evgeny_s Jun 13 '17 at 10:57

0 Answers0