free hit counter

Post on facebook page with the facebook php SDK

Post on facebook page with the facebook php SDK

I hope you have a facebook page and a App 🙂

Post on facebook page with the facebook php SDK

Post on facebook page with the facebook php SDK

Many time we need to auto post in facebook page wall when we post new article , post , image , video anything in our web site.

So how to do this …. lets start


< ? php r equire ‘../src/facebook.php’; $f acebook = new Facebook(array( ‘appId’ => ‘XXXXXXXXXXXXXXXXX’,
‘secret’ => ‘XXXXXXXXXXXXXXXXX’,
));

// Get User ID
$user = $facebook->getUser();

if ($user) {
try {
$page_id = ‘XXXXXXXXXXXXXXXXX’;
$page_info = $facebook->api(“/$page_id?fields=access_token”);
if( !empty($page_info[‘access_token’]) ) {
$args = array(
‘access_token’ => $page_info[‘access_token’],
‘message’ => ‘PHP Lab!’,
‘name’ => ‘PHP Lab!’,
‘caption’ => “PHP Lab”,
‘link’ => ‘http://lab.yogeshsaroya.com’,
‘description’ => ‘PHP Lab ‘,
‘picture’ => ‘http://lab.yogeshsaroya.com/wp-content/uploads/2012/06/logo1.png’,
);
$post_id = $facebook->api(“/$page_id/feed”,”post”,$args);
}
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}

// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array(‘scope’=>’email,offline_access,manage_pages,publish_stream’));
}
? >

 

 

Donwlad Facebook SDK With this code

 

Leave a Reply