我使用以下代码发布到电子邮件的粉丝:
$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,
发布为我的用户名而不是粉丝专页,可能是什么问题?
答案 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);