Publish facebook page status or wall post automatically
Posted by mahmud ahsan on December 17, 2009 in
Facebook, PHP | 13 Comments
Facebook page is now very popular. Many companies and people create facebook page for their own publicity. Suppose your company has 100 products and they want to maintain 100 facebook pages, then isn’t it very difficult to update status all of the pages manually?
In this article, I’ll show and discuss about 2 facebook api, using that you can easily update your facebook page status or publish wall post on that page automatically
I assume that you know how to set cron from hosting admin panel, I also assume that you have intermediate knowledge of facebook application development and their api usage.
At first you’ve to setup a new facebook application. In the application setting look Authentication and in the Authentication setting must tick Facebook Pages
Now save the api and secret key either in your database or config file.
Update Status or Publish in Wall of your facebook page:
To update status of a facebook page, you must have to become an admin of that page. Now add the newly created application on that facebook page.
To add application in your facebook page: visit http://www.facebook.com/apps/application.php?id=XXXXXXXXX where XXXXXXXX is the id of your newly created application. Now click Add to my page
This will show you a list of pages. If you don’t see your desire facebook page, remember either you don’t an admin of that page or you already added this app on that page.
To update page status, you need extended permission. Write a php script for your facebook application and run that script inside facebook. Like http://apps.facebook.com/yourapps/permission.php
//filename: permission.php
<script type="text/javascript">
function addFbAutostatus(id){
Facebook.showPermissionDialog('status_update', null, true, [id]);
}
function addFbAutoWallPostPublish(id){
Facebook.showPermissionDialog('publish_stream,offline_access', null, true, [id]);
}
</script>
<a href="#" onclick="addFbAutostatus('XXXXXXXXXXXx'); return false;">Page Status Update</a> //replace XXXXXXXX by your facebook page id
<a href="#" onclick="addFbAutoWallPostPublish('XXXXXXXXXXXx'); return false;">Page Wall Update</a> //replace XXXXXXXX by your facebook page id
In the canvas page, you’ll see the link Page Status Update, click it and accept the permission if you only update status. If you want to publish photos/videos on page wall then you’ve to click Page Wall Update and to accept those permissions.
Now write a script that will update your facebook page status or publish wall post:
//filename: cron.php
include_once "config.php";
$facebook = new Facebook($config['api_key'], $config['secret_key']);
$status = "Sample Status";
$pageid = XXXXXXXXX; //replace it by your desire facebook page id
try {
$status = $facebook->api_client->users_setStatus($status, $pageid);
}
catch(Exception $o ){
print_r($o);
}
/*if you want to publish wall post in facebook page, then you have to use another method and remember for this method call you've set your user id and session key, here i just shown how to publish status using stream_publish method, but you can also publish video, image as wall post using stream_publish method
$user = your user id and $session_key = your facebook session key, you can obtain them by
$user = $_REQUEST['fb_sig_user'];
$session_key = $_REQUEST['fb_sig_session_key'];
And don't forget to save them in database, because you'll need them when you will use cron.php from offline
*/
try {
$facebook->set_user($user, $session_key);
$facebook->api_client->stream_publish($status, null, null, $item['pageid']);
}
catch(Exception $o ){
print_r($o);
}
Now run in browser: http://yoursite.com/yourfbappdir/cron.php
And check the page, you’ll see you facebook page’s status updated.
If you want to predefine many statuses and update them automatically, then create an admin panel and database from where you’ll add many statuses, and make the cron.php more dynamic and set it as cron. So that cron.php catch statuses one by one from database and based on publish-date it will update your facebook page by updated status.
To learn more about stream_publish method: Click Here
To learn more about users_setStatus: Click Here
Related Posts
If you think this article kicked ass, subscribe to the RSS feed or follow me on Twitter! Share with your friends, or leave a comment below (or better still, do both!)Comments (13)





hi mahmud ahsan,
This is very good article u post, but message we posting to wall as a fan , but not admin.., so i can’t share messages with other fans, do u have any suggestions so that i can post as a Page not as fan.,
i mean to say that, what ever i am publishing is showing under “Just Fan” , but i want it show in “Just Page_name”., i used $user = userId, and $item['pageid'] = MyPage id..,
I am new to PHP ..
@Kalyan, if you use users_setStatus this method then page update will occur as page admin. If you want to use stream_publish then click setting in page wall and set Default View for Wall: Posts by Page and Fans. Then all wall posts you will see in the same page.
Hi,
thank you mahmud ahsan, for your response,
While i am updating status update, I had occurred with following
Updating status requires the extended permission status_update
I know that is bcoz, that Need to have extended permission, i with URL, http://www.facebook.com/authorize.php?api_key=YOUR_API_KEY&v=1.0&ext_perm=PERMISSION_NAME
That is because, i dont understand how to use permission.php
@kalyan, you just need to prompt user for extended permission. If user granted it, then you don’t have to worry about how you could use it. Just call the api status_update and it will update your page status.
hi, Ahsan
I am trying in different ways ways to publish on page wall, Let now i created new application & page.., by accessing permission.php nothing is done for me,
can u say how to use permission.php.
presently i occurred with following error, while doing status update.
Updating status requires the extended permission status_update
thank you for all you’r response.
Hello
This is a nice post.You have given very useful application that can easily update facebook page status or publish wall post on that page automatically..Thank you very much for giving such a good information.
well thanks, it’s pointing me in a better direction. but it’s a very vague article… and if you havent already been trying this for a while you’ll be totally lost.
Great article. I read like 5 before finding this one… and this one actually got it working for me! Thanks!
Great article, but it didn’t worked for me, it always give me 201 or not enough permission. This link helped me:
http://spletnisistemi.si/blog/2010/04/29/facebook-aplikacija-kako-poslati-status-na-fan-page-wall-kot-fan-preko-php-ja/
hi,
this is very good article for publishing to walls, Ahsan provided lot of information.
if still you find any problem to publish run following URL,
• To Grant permissions to Application to access your Wall, feeds
http://www.facebook.com/connect/prompt_permissions.php?api_key=API_KEY&v=1.0&next=http://www.facebook.com/connect/login_success.html?xxRESULTTOKENxx&display=popup&ext_perm=read_stream,publish_stream&enable_profile_selector=1
Hi Ahsen,
I checked your code. The problem that I can not use publish_stream. Could you give us a clear example with publish_stream. Thank you very much
Hi Mahmud Ahsan how to publish offline with new graph api ?
Thank you very much