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
* 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 and save the changes.


post to fb
Now download Facebook PHP SDK here:

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.

include_once 'src/facebook.php';

$returnurl = 'YOUR_PAGE_URL';
$permissions = 'manage_pages, publish_stream';

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

$fbuser = $fb->getUser();


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

$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));

echo 'The user does not have any pages.';
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();

$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:

Link original