我正在使用此代码发布到我的用户个人资料页面,它在发布到我的个人资料时效果很好(我设置在$ id我的脸书用户ID),但当我尝试发布到我的脸书页面时(不是我的个人资料页面)我在$ id中设置了facebook页面ID,然后脚本不再工作了,我收到了以下错误
{"error":{"message":"(#200) The user hasn't authorized the application to perform this action","type":"OAuthException","code":200}}
这是我的代码
<?php
class Facebook
{
/**
* @var The page id to edit
*/
private $id = '<FACEBOOKPAGEID>';
/**
* @var the page access token given to the application above
*/
private $app_access_token = "<MYAPPACCESSTOKEN>";
/**
* @var The back-end service for page's wall
*/
private $post_url = '';
/**
* Constructor, sets the url's
*/
public function Facebook()
{
$this->post_url = 'https://graph.facebook.com/' . $this->id .'/feed';
}
/**
* Manages the POST message to post an update on a page wall
*
* @param array $data
* @return string the back-end response
* @private
*/
public function message($data)
{
// need token
$data['access_token'] = $this->app_access_token;
// init
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// execute and close
$return = curl_exec($ch);
curl_close($ch);
// end
return $return;
}
}
$facebook = new Facebook();
echo "<pre>";
echo $facebook->message(array( 'message' => 'Message',
'link' => 'http://www.mylink.com/',
'picture' => 'http://www.mylink.com/pic.jpg',
'description' => 'My description' ) );
echo "</pre>";
?>
我正在使用app_access_token,因为它没有改变,我不需要登录Facebook即可发布到我的Facebook页面
知道为什么这对我的个人资料页面而不是我的脸谱页面有用吗?