Posting to a Facebook fan page directly from your PHP-based website can be a handy feature. However, finding up-to-date tutorials can be a challenge.
To post to your fan page, you need to obtain the necessary permissions and page access token.
In your PHP script, define the page access token and page ID obtained in Step 1:
$page_access_token = 'XXXXXXX'; $page_id = 'YYYYYYYY';
Create an array containing the post data:
$data = [ 'picture' => "http://www.example.com/image.jpg", 'link' => "http://www.example.com/", 'message' => "Your message", 'caption' => "Caption", 'description' => "Description", 'access_token' => $page_access_token, ];
Set the post URL:
$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';
Use cURL to post the message:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $post_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $return = curl_exec($ch); curl_close($ch);
After executing the PHP script, the post should appear on your Facebook fan page.
The above is the detailed content of How to Post to a Facebook Fan Page from your PHP Website?. For more information, please follow other related articles on the PHP Chinese website!