O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Publishing News and Mini-Feed Stories

Problem

I want to publish stories about my users’ activities in my app so that their friends see them and become engaged.

Solution

Use the Feed.publishUserAction() method:

$template_bundle_id = 12345678901;

$template_data = array(
    'nap-type'=>'Super Disco Nap',
    'status'=>'fabulous',
);

$target_ids = '12345,67890';

$result = $facebook->api_client->feed_publishUserAction
($template_bundle_id, json_encode($template_data), $target_ids);

You can optionally include a fourth parameter, body_general, to add additional body content to extend short story format posts. If these stories are being aggregated, Facebook will include one of the body_general parameters in the aggregated story. See Three Story Sizes: Working with Template Bundles for more information about template bundles.

Discussion

Your app used to be limited to calling this function once every 12 hours for every user other than those listed as developers for your app (who will always see every story that you publish for testing purposes). At the time this book was going to press, it remained unclear as to whether that would continue to be the case with the Profile redesign.

Note that the template_data needs to be JSON-encoded when you pass it into the Feed.publishUserAction() method.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required