1. Facebook page
2. Your user never ending access token. Here normal guide how to get it https://medium.com/@Jenananthan/how-to-create-non-expiry-facebook-page-token-6505c642d0b1
3. Get your pageId. Go to your page Information (or About)->In the very bottom your pageId. At the moment of the article it is here https://www.facebook.com/pg/<pageUrl>/about/. Where <pageUrl> is your facebook page slug.
4. Get facebook php sdk https://github.com/facebook/php-graph-sdk with composer
composer require facebook/graph-sdkNote: this command is good at the moment of this article. But you better go to github and copy, because they can change it.
Now here the script
$appId = ''; //your App Id
$appSecret = ''; //your app secret
$pageId = '0000000000'; //id of the page you want to publish on
$userAccessToken = ''; //Your never expire user access token
$fb = new \Facebook\Facebook([
'app_id' => $appId,
'app_secret' => $appSecret,
'default_graph_version' => 'v3.0',
]);
$linkData = [
'link' => 'http://google.com', //TODO change
'message' => "My message", //TODO change
];
$longLivedToken = $fb->getOAuth2Client()->getLongLivedAccessToken($userAccessToken);
$fb->setDefaultAccessToken($longLivedToken);
$response = $fb->sendRequest('GET', $pageId, ['fields' => 'access_token'])
->getDecodedBody();
$foreverPageAccessToken = $response['access_token'];
$fb->setDefaultAccessToken($foreverPageAccessToken);
$response = $fb->post("/$pageId/feed", $linkData);
Note: If you're using github then values for first 4 variables should be outside of git. For example in env file or php file which is in gitignore.