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.

Get Facebook Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.