开发者

Facebook PHP API not posting to fan page

I am running a page that utilizes the Facebook PHP SDK to post a Facebook update to a Facebook fan page. I have setup the app, a开发者_如何转开发llowed full access (offline access, manage pages, stream update) to the user account, made sure I am the admin to the fan page and generated the access token. Here is the code I am using to test this:

$APP_ID = '****';                       
$APP_SECRET = '*****';          
$PAGE_ID = '****';                          
$ACCESS_TOKEN = '****';

//Initiate a facebook instance
$facebook = new Facebook(array(
  'appId'  => $APP_ID,
  'secret' => $APP_SECRET,
  'cookie' => true,
));

//To keep this as simple as possible, we'll only be posting a message to the wall with our access token we received from accounts
$attachment = array('message' => "test", 'access_token' => $ACCESS_TOKEN);

$result = $facebook->api('/'.$PAGE_ID.'/feed', 'post', $attachment);

if($result){ 
    echo "<p>Posted status update</p>";
}

This gives me a success message but does not actually post anything to anywhere. If I change this line:

$result = $facebook->api('/'.$PAGE_ID.'/feed', 'post', $attachment);

to this:

$result = $facebook->api('/me/feed', 'post', $attachment);

It works like a charm and posts the update to the my Facebook wall, and not my fan page. All of the tutorials I have seen and questions I have read on here lead me to believe that my code should be posting to my fan page, what am I missing?


Is this your own Page, or are you trying to post to a page you're a fan of instead?

If this is your page, use the page access token you can retrieve at the /me/accounts endpoint to post as the page

If it's not, you must like the Page before you can post on its wall

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜