多墙发布网站脚本。没有显示粉丝页面列表时出错

时间:2012-06-10 12:32:14

标签: php facebook facebook-php-sdk facebook-access-token facebook-app-requests

$queries = array(
    array('method' => 'GET', 'relative_url' => '/'.$user),
    array('method' => 'GET', 'relative_url' => '/'.$user.'/pages'),
    array('method' => 'GET', 'relative_url' => '/'.$user.'/groups'),
    array('method' => 'GET', 'relative_url' => '/'.$user.'/friends'),
    );

// POST your queries to the batch endpoint on the graph.
try{
    $batchResponse = $facebook->api('?batch='.json_encode($queries), 'POST');
}catch(Exception $o){
    error_log($o);
}

//Return values are indexed in order of the original array, content is in ['body'] as a JSON
//string. Decode for use as a PHP array.
$user_info  = json_decode($batchResponse[0]['body'], TRUE);
$pages      = json_decode($batchResponse[1]['body'], TRUE);
$groups     = json_decode($batchResponse[2]['body'], TRUE);
$friends_list= json_decode($batchResponse[3]['body'], TRUE);

我怀疑这个数组/'.$user.'/pages'是错误的。我遇到很多麻烦。可能是一个简单的错误。

array('method' => 'GET', 'relative_url' => '/'.$user.'/pages'),

1 个答案:

答案 0 :(得分:0)

使用 $ user_profile [id] 尝试{},同时确保您有显示此用户信息所需的权限。

$user = $facebook->getUser();
$access_token = $_SESSION['fb_APPID_access_token'];
if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');

  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}