Facebook Auto Poster in PHP

0

Hello Friends !

I have my website where I added social shares button, but it was a bit struggling to post on Facebook by clicking my posts on daily basis here I found a piece of code that reduced all my efforts. It is very efficiently, then I decided to share this code with you. This Facebook r code can be used as auto posting plugin also, you can customize this code into any framework.


// require Facebook PHP SDK 

// see: https://developers.facebook.com/docs/php/gettingstarted/ 

require_once("/YOUR_PATH_TO/facebook_php_sdk/facebook.php");

// initialize Facebook class using your own Facebook App credentials  

// see: https://developers.facebook.com/docs/php/gettingstarted/#install 

$config = array();
$config['appId'] = 'YOUR_APP_ID';
$config['secret'] = 'YOUR_APP_SECRET';
$config['fileUpload'] = false; // optional

$fb = new Facebook($config);

// define your POST parameters (replace with your own values) 

$params = array(
"access_token" => "YOUR_ACCESS_TOKEN", // see: https://developers.facebook.com/docs/facebook-login/access-tokens/
"message" => "Here is a blog post about auto posting on Facebook using PHP #php #facebook",
"link" => "http://www.pontikis.net/blog/auto_post_on_facebook_with_php",
"picture" => "http://i.imgur.com/lHkOsiH.png",
"name" => "How to Auto Post on Facebook with PHP",
"caption" => "www.pontikis.net",
"description" => "Automatically post on Facebook with PHP using Facebook PHP SDK. How to create a Facebook app. Obtain and extend Facebook access tokens. Cron automation."
);

// post to Facebook
// see: https://developers.facebook.com/docs/reference/php/facebook-api/
try {
$ret = $fb->api('/YOUR_FACEBOOK_ID/feed', 'POST', $params);
echo 'Successfully posted to Facebook';
} catch(Exception $e) {
echo $e->getMessage();
}

Share.

About Author

Leave A Reply