1

我使用以下代码将消息发布到粉丝页面:

$message = "test";
$link = "http://test.com";
$pageid = "123456789";
$post_url = '/'.$pageid.'/feed';
$msg_body = array(
'message' => $message,
if ($fbuser) {
try {
$postResult = $facebook->api($post_url, 'post', $msg_body );
} catch (FacebookApiException $e) {
echo $e->getMessage();
}
}else{
$loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
header('Location: ' . $loginUrl);
}

并且工作正常(作为粉丝页面名称发布),但如果我改变:

'message' => $message,

'link' => $link,

以我的用户名而不是粉丝专页发布,可能是什么问题?

4

1 回答 1

1

您必须获得为此页面授予的访问令牌,并在发布时使用它:

$accounts = $facebook->api('/me/accounts');
foreach($accounts['data'] as $account){
   if($account['id'] == $pageid){
      $token = $account['access_token'];
   }
}
$msg_body = array(
    'link' => $link,
    'access_token' => $token
);
$postResult = $facebook->api($post_url, 'post', $msg_body);
于 2012-12-30T09:22:53.360 回答