To publish news feeds, older applications used one of the following methods: feed.publishStoryToUser, feed.publishActionOfUser, and feed.publishTemplatizedAction. But due to the changes in the New Facebook, these methods no longer work. As a result, these applications are only able to publish news feeds if the user is still using the old facebook. But, when used in the new UI, no feeds are published.
While trying to make some of our legacy apps to work in the new facebook, I found that doing it is not really a very difficult task. But, unfortunately I didnt find good docs that explained the procedure clearly, and easily. Here I will try to explain the procedure with a simple example.
Suppose, in our legacy app, we have the following code to publish a news feed:
<?php ... $facebook->api_client->feed_publishTemplatizedAction( '{actor} has bought {item} from The Wonderful App', '{"item": "' . $item_name .'"}' ); ... ?>
Now the above code will publish a simple one line news feed in the old facebook. But if the users are in the new one, this code will not result in any feed publishing at all. To make it publish feed in both the old and new Facebook, we just need to follow these 4 steps:
1. Update Facebook library classes
The first thing that we need to do is to update the facebook library classes. Download the latest code, and replace the files “facebook.php” and “facebookapi_php5_restlib.php” with the newly downloaded versions. In the class FacebookRestClient (facebookapi_php5_restlib.php), we will notice the following new methods:
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | public function &feed_registerTemplateBundle($one_line_story_templates, $short_story_templates = array(), $full_story_template = null) { $one_line_story_templates = json_encode($one_line_story_templates); if (!empty($short_story_templates)) { $short_story_templates = json_encode($short_story_templates); } if (isset($full_story_template)) { $full_story_template = json_encode($full_story_template); } return $this->call_method('facebook.feed.registerTemplateBundle', array('one_line_story_templates' => $one_line_story_templates, 'short_story_templates' => $short_story_templates, 'full_story_template' => $full_story_template)); } public function &feed_getRegisteredTemplateBundles() { return $this->call_method('facebook.feed.getRegisteredTemplateBundles', array()); } public function &feed_getRegisteredTemplateBundleByID($template_bundle_id) { return $this->call_method('facebook.feed.getRegisteredTemplateBundleByID', array('template_bundle_id' => $template_bundle_id)); } public function &feed_deactivateTemplateBundleByID($template_bundle_id) { return $this->call_method('facebook.feed.deactivateTemplateBundleByID', array('template_bundle_id' => $template_bundle_id)); } public function &feed_publishUserAction($template_bundle_id, $template_data, $target_ids='', $body_general='') { return $this->call_method('facebook.feed.publishUserAction', array('template_bundle_id' => $template_bundle_id, 'template_data' => $template_data, 'target_ids' => $target_ids, 'body_general' => $body_general)); } |
Here we will be using two from the above new methods: feed.registerTemplateBundle and feed.publishUserAction.
2. Add asterisks(*) before and after token names in the template
The next thing that we need to know is to add asterisks(*) before and after any token that we use in our template. So our new template will look like this:
"{*actor*} has bought {*item*} from The Wonderful App"I am still not sure why we need to do this, but the docs says so.
3. Register the template bundle and get the Template Bundle ID
This is the most critical, and boring, part of the whole process. In the new API, we need to register all templates that we plan to use. Once a template is registered, the API returns a Template Bundle ID that is needed to publish a news feed template. To register a template, and get a Template Bundle ID, we need to call the method feed.registerTemplateBundle. This has to be done separately, and before we start using the template. Here is a simple script that we can add to our App to register our template:
<?php $template = "{*actor*} has bought {*item*} from The Wonderful App"; echo $facebook->api_client->feed_registerTemplateBundle($template); ?>
When we execute the script, it will print the Template Bundle ID for the template. We will need this ID later, to publish feeds based on this template. Please note that the above script is a very simplified version, and is only useful to register our example template. Also, this assumes that we are only interested to register one line story for the feeds. There are two other types of story (short and full) supported by the new API that we are ignoring here, for simplicity’s sake. We will only need to execute the script ones to get the Template Bundle ID. Lets assume that our Template Bundle ID is 73684790233. We will need this to publish the story.
4. Use feed.publishUserAction instead of feed.publishTemplatizedAction
We are almost done! All we need to do now is to use our Template Bundle ID to publish the story. But instead of using feed.publishTemplatizedAction to publish the feed, we will use the new method feed.publishUserAction as shown below:
<?php ... $facebook->api_client->feed_publishUserAction( 73684790233, '{"item": "' . $item_name .'"}' ); ... ?>
Notice, we didnt need to pass the template. Instead we passed the Template Bundle ID that we got earliar, when we registered the template. We also passed the data, just like before.
Please note that this is a simplified version of the process that we need to follow to make feeds publishing work in apps that still uses the old API. For a more detailed understanding please refer the following:
Thats all guys! I hope this is useful. Thanks for reading.

1 trackbacks/pingbacks
Anupom // September 06th 2008
I don’t know that much about facebook app development. But I think I got many points reading your post. It is so wonderfully written and well explained. Thanks Ahsan vai for this excellent stuff and please do blog regularly.
Md. Mahmud Ahsan // September 06th 2008
Hey Ahsan vai, nice post!
Thanks for publishing the latest implementation techniques of Feeds!
Ahsan // September 06th 2008
@Anupom @Mahmud: Thanks guys
Manzil // September 07th 2008
Thanks Ahsano, for this nice and informative post. I am sure this post will be very helpful to thousands of developers out there who got stuck with the new Fbook’s news and mini feed problem.
Sunil // September 12th 2008
Thanks for this helpful info. I’m still fuzzy on one point: do we register the bundle once ever? or once per session?
If only once ever, they should have a form we could fill out to register bundles online, once, be able to go back and edit them and so forth.
Otherwise it make some sense to register them once per session, to get the bundle id, but then what’s the point of that?
Ahsan // September 12th 2008
@Sunil We just need to register the feed bundle once, and just once. Yes, facebook should have had a form to register feeds, but I didn’t find any. But, once you register feed bundles for an app, you can view/deactivate them from here: http://developers.facebook.com/tools.php?templates
Ahsan // September 12th 2008
UPDATE: the new facebook feed bundle registering is working now: http://developers.facebook.com/tools.php?feed . This can be used to register feed bundles instead of the painful step#3 above.
Florin Pandelea // October 08th 2008
This is a very useful article. I have read a lot of documenation how could I do something like explained in this article, the Facebook documentation is totally a mess. Thank you very much for sharing this with us.
Cheers.
Developer // October 15th 2008
Very nice, flow good, I’ve just convert this to C# works great, Thanks!!!
TC // October 17th 2008
Hey this was really useful for me thanks for posting!
Facebook Application Scripts // November 25th 2008
Great article! You explained everything very clearly
Janos // April 02nd 2009
Thanks for this info. Its working perfectly.
You can follow any responses to this entry via its RSS comments feed. You may also leave a trackback by clicking this link.