I have read at many places that Facebook made some changes around 2018 that prevent people from posting as a page with PHP. I researched for a while to see if I can still auto post on a Facebook page if I am its Admin.
My sources: Facebook Graph API v3.1 Access Token Permission Limitations For Developers and https://adamboother.com/blog/automatically-posting-to-a-facebook-page-using-the-facebook-sdk-v5-for-php-facebook-api/
I am the only one who will use this auto-post app and I am the admin of the page on which I will be posting these links.
Here is the code I tried:
$fb = new FacebookFacebook([
'app_id' => 'app_id',
'app_secret' => 'app_secret',
'default_graph_version' => 'v2.2',
]);
$pageAccessToken = "page_access_token";
$linkData = [
'link' => 'some_link',
'message' => 'some_message'
];
try {
$response = $fb->post('/me/feed', $linkData, $pageAccessToken);
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: '.$e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: '.$e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
Running the above code, I get the following error:
Graph returned an error: (#200) If posting to a group, requires app
being installed in the group, and either publish_to_groups
permission with user token, or both manage_pages and publish_pages
permission with page token; If posting to a page, requires both
manage_pages and publish_pages as an admin with sufficient
administrative permission.
Now, I am an admin of the page. I also have selected manage_pages
and publish_pages
in permissions. So, why am I getting this error?
3
Answers
You are most likely not using a Page Token, but a User Token. It still works, but you must use a Page Token to post to a Page.
According to the documentation here, you can not publish posts by using the
feed
edge anymore. This documentation discusses editing and deleting the posts, it also says we can not create new posts.On May 5, 2020, Facebook released six new Page permissions to replace the manage_pages and publish_pages permissions. Taking advantage of curl, you can use php to create and update a post or comment, reply to a post or comment, and delete a post or comment, on your Facebook Page Feed as the Page.
Send a POST request to the /{page-id}/feed endpoint:
curl -i -X POST “https://graph.facebook.com/{page-id}/feed
?message=Hello Fans!
&access_token={page-access-token}”
On success, your app receives the following response:
{
“id”: “{page-post-id}”
}
source: https://developers.facebook.com/docs/pages/publishing/