Posting to Facebook fan page feed as user through

2019-07-20 06:38发布

I'm currently facing a problem with the Facebook API that did not occur in summer 2012. In a facebook app of mine, the user is able to type in some text into a textarea which is then posted to a facebook fanpage, just as he went to the page on facebook himself and posted it there.

Therefore my app requires the publish_stream extended permissions in order to be able to post onto the pages feed.

To settle the post itself I was doing the following:

try{
    $response_object = $fb->api('XXX/feed', 'POST', array(
        'message' => $input->post('user_text'),
    ));     
}
catch(Exception $e){
    die($e->getMessage());
}

Last year this was working without any problems. On the Page's feed (PageId replaced with XXX in code snippet above) there a post appeared on the page by the user that used the app.

To my surprise the exception in the snippet above was cought when I tried to do the same today. I didn't change anything the way I process data with the fb API.

The message I got was the following:

(#283) Requires extended permission: manage_pages

I don't need to post to the wall as the page administrator but as the user. I retrieved the users access token when authorizing with the publish_stream permissions and I don't want to have the manage_pages permission since I just don't need to manage the users page.

What I want to do is simply post to a fan page as the user that is using the app.

Did facebook change anything lately on the "post-to-feed procedure" or did I personally miss something?

Thanks in advance Thomas

2条回答
够拽才男人
2楼-- · 2019-07-20 07:38

This can be linked with issue, which prohibits users who are administrator of the given page, to post on that pages' feed (as user not as page).

Check if the same happens if you are trying to post as average user (not as administrator of page). From my experience, avg. user can do that if application has permissions: publish_stream, publish_action.

Here is my bug report: https://developers.facebook.com/bugs/167764356741336?browse=external_tasks_search_results_51f780dd6e9da2d82532422

查看更多
看我几分像从前
3楼-- · 2019-07-20 07:42

Sorry for being so egoistic. I've solved the problem a few days after I asked the question here. Don't ask me why, but by using CURL when posting to a pages feed as a user everything works as expected.

<?php

$postfields = array(
    'message' => 'The message to be posted on the feed',
    'link'    => 'http://anyurl.com',
    'access_token' => 'A_VALID_USER_ACCESS_TOKEN', // This is the important part, don't miss it
);

$posturl = 'https://graph.facebook.com/PAGE_ID/feed';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $posturl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);    

?>

Note that you are not allowed to post predefined content, but always allow the user to post a message. Otherwise facebook will suspend your app from being allowed to post to page feeds.

查看更多
登录 后发表回答