1

当我尝试让用户发帖时,它只显示“数组([数据] => 数组())”(配置文件显示,我可以发布到墙上)。当我将“我”更改为公共页面时,它会起作用。登录链接和用户信息显示。请帮助我,我不明白为什么它不起作用!

<?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>
4

1 回答 1

0

您需要登录时的 read_stream 权限。所以您需要用以下内容替换您的 getLoginUrl() 调用。您还可以添加更多以逗号分隔的权限,例如:'read_stream,publish_stream,etc...'

$url = $facebook->getLoginUrl(array('scope' => 'read_stream'));
于 2013-08-09T13:50:14.793 回答