em Scripts PHP

Criando aplicativo em PHP para publicar na página do mural do Facebook

Tutorial em inglês

In this tutorial you can learn how to post in Facebook Page wall from a PHP application.

post to FB
For this tutorial i have created a sample page named ‘New Movies’. You can create a page by using ‘Create Page’ option present in your facebook dashboard.

 

post to fb

Also i have created a Facebook App named ‘Newmoviesapp’ by which am going to connect with facebook.

To create a facebook application…

* Go to https://developers.facebook.com/apps
* Login with your facebook credentials
* If you are not verified your mobile number with facebook you will be prompted to verify it.
* Click on “Create New App” and fill out the form.
* Once you created the app, under “Website with Facebook Login” add your project URL (i.e http://yourdomain.com/postfofbpage.php) and save the changes.

 

post to fb
Now download Facebook PHP SDK here: https://github.com/facebook/facebook-php-sdk

Find the ‘src’ folder from the SDK download and keep it in your project folder. Create ‘postfofbpage.php’ file in the place where your ‘src‘ folder exists and place the following code.

Dont forgot to replace ‘APPID_FROM_FACEBOOK‘, ‘APPSECRET_FROM_FACEBOOK‘ and ‘YOUR_PAGE_URL‘ with your Facebook App details.

<?php
include_once 'src/facebook.php';

$appId = 'APPID_FROM_FACEBOOK';
$secret = 'APPSECRET_FROM_FACEBOOK';
$returnurl = 'YOUR_PAGE_URL';
$permissions = 'manage_pages, publish_stream';

$fb = new Facebook(array('appId'=>$appId, 'secret'=>$secret));

$fbuser = $fb->getUser();

if($fbuser){

if(isset($_POST['msg']) and $_POST['msg']!=''){
try{
$message = array(
'message' => $_POST['msg']
);
$posturl = '/'.$_POST['pageid'].'/feed';
$result = $fb->api($posturl,'POST',$message);
if($result){
echo 'Successfully posted to Facebook Wall...';
}
}catch(FacebookApiException $e){
echo $e->getMessage();
}
}

try{
$qry = 'select page_id, name from page where page_id in (select page_id from page_admin where uid ='.$fbuser.')';
$pages = $fb->api(array('method' => 'fql.query','query' => $qry));

if(empty($pages)){
echo 'The user does not have any pages.';
}else{
echo '<form action="" method="post">';
echo 'Select Page: <select name="pageid">';
foreach($pages as $page){
echo '<option value="'.$page['page_id'].'">'.$page['name'].'</option>';
}
echo '</select>';
echo '<br />Message: <textarea name="msg"></textarea>';
echo '<br /><input type="submit" value="Post to wall" />';
echo '</form>';
}

}catch(FacebookApiException $e){
echo $e->getMessage();
}

}else{
$fbloginurl = $fb->getLoginUrl(array('redirect-uri'=>$returnurl, 'scope'=>$permissions));
echo '<a href="'.$fbloginurl.'">Login with Facebook</a>';
}

?>

Now execute postfofbpage.php in browser and check the output. The Page will ask you to give permission for the app to post in your page wall.

post to fb

Once you accept it you will be redirected to your php app where you can see a form by which you can post a status message to your facebook page wall.

post to fb

– See more at: http://www.detailsinn.com/c7f76878ca736e015b7a94bf3036136c1357649641-article-posting-in-facebook-page-wall-from-a-php-application.html#sthash.dv0lKA0Y.dpuf

Link original
http://www.detailsinn.com/c7f76878ca736e015b7a94bf3036136c1357649641-article-posting-in-facebook-page-wall-from-a-php-application.html