简体   繁体   中英

Cant get users posts with facebook php sdk

When I try to get the users posts it just shows "Array ( [data] => Array ( ) )" (the profile shows and I can post to the wall). It works when I change "me" to a public page. The Login-link and user-info shows. Please help me, I don't get why it doesn't work!

<?php
session_start();
require 'facebook/facebook-php-sdk/src/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => 'xxxxxxxxxxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxxx',
));
// Get User ID
$user = $facebook->getUser();

if ($user)
{
    $url = $facebook->getLogoutUrl();
}
else
{
    $url = $facebook->getLoginUrl();
}

if ($user) {
  try {
      $pageFeed = $facebook->api('me' . '/feed');
      print_r($pageFeed);
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
        error_log($e);
    $user = null;
  }
}
?>

<a href="<?php echo $url; ?>">LOGIN!</a>
<pre><?php print_r($user_profile); ?></pre>

You need the read_stream permission on Login. so you need to replace your getLoginUrl() call with the following. You could also add more permissions separated by comma, Ex: 'read_stream,publish_stream,etc...'

$url = $facebook->getLoginUrl(array('scope' => 'read_stream'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM