PHP发布链接到Facebook作为页面而不是用户

时间:2012-12-30 09:05:07

标签: php facebook

我使用以下代码发布到电子邮件的粉丝:

$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,

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

1 个答案:

答案 0 :(得分: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);