How to Successfully Publish Widespread News Feed Stories

January 21, 2008

Since the availability of the Facebook Platform’s feed.publishTemplatizedAction API call, developers have had the opportunity for stories to be shared with friends who have not yet installed their application. However, the method is significantly more difficult to comprehend than the previously used feed.publishActionOfUser. On top of the much greater learning curve in trying to understand the concepts of templatized actions, the various updates to this API call have created even more difficulties for both novice and experienced Platform developers.

Templatized Feed Actions

Why Use Templatized Feeds?

One of the more common questions asked by developers is what benefit templatized feeds offer. The answer is simple: aggregation. Stories published by applications are not guaranteed to appear on friends’ News Feeds; aggregation helps promote news feeds when used correctly. Essentially, the likelihood of users encountering a story for an application on their News Feed increases as the number of similar (templatized) stories that an application publishes increases. We’ll come back to this point shortly.

Method Components

In first learning feed.publishTemplatizedAction, there are 5 to 6 parameters with which it is of dire importance to become acquainted with.

The first 4 of these parameters are the title_template, title_data, body_template, and body_data. The template parameters (title_template and body_template) represent commonly occurring pieces of information that will be consistent from feed item to feed item. Templates are simple text values that outline the sentences in the story. Variables are encased in curly brackets, with {actor} and {target} being reserved keywords that represent the names of the actor and target users.

Below are several examples of feed templates.

{actor} just bought a new {item}.
{actor} just slapped {target}!
{actor} gave {target} <fb:if-multiple-actors>candy hearts<fb:else>a candy heart</fb:else></fb:if-multiple-actors>

The two data parameters (title_data and body_data) represent data specific to one feed action that must be inserted into the respective templates. These parameter values must be passed as JSON-encoded data. Fortunately, PHP5.2 users have the advantage of a built-in json_encode function. Other PHP developers will need to manually generate their JSON or utilize a custom-built json_encode equivalent.

The following demonstrates several example pieces of data.

{"item":"Super Mario Brothers 3"}
{"book":"The Art of the Deal","url":"http:\/\/apps.facebook.com\/mybooks\/view\/452"}

The next parameter of importance is the body_general. The body_general allows more information specific to one particular story to be provided. Unlike the body_template, the body_general is not aggregated. Instead, when feed actions of a specific template are aggregated, only one random user’s body_general text is displayed to whomever is reading the story.

The last important parameter of note is the target parameter. This is a comma-delimited list of users that are the target of a user’s actions. For example, if John poked Betsy, Betsy is the target of the action (John being the actor). Setting the target parameter to Betsy’s user ID would be a valid use. If John poked Betsy and Cameron, then Betsy and Cameron would be the targets, in which case both user ID’s would be passed as the parameter (separated by a comma).

Images and image link URL’s can be provided in a feed story as well; however, they will not be explained in depth here due to the simplicity in using them relative to the remainder of the feed.publishTemplatizedAction method.

Example Implementations

The following example illustrates a very simple implementation of feed.publishTemplatizedAction.

// Prepare the feed data and layout.
$titleTemplate = '{actor} hit {target} with {item}!';
$titleData = json_encode(array(
	'item' => 'a water balloon',
));
$target = $_POST['target_id'];

// Perform the API method call.
$facebook->api_client->feed_publishTemplatizedAction(
	$titleTemplate, $titleData, '', '', '',
	null, null, null, null, null, null, null, null,
	$target);

The result is a one-line (title-only) story, reading something like “Matt Huggins hit Joe Shmoe with a water balloon!” Obviously, the exact text would depend upon the actors and targets involved in the action. The following screen shot shows how such a feed story would appear.

Templatized Action Example

This example is very basic. It does not provide any details regarding the story, and there is no imagery utilized to grab the attention of the reader. The next example demonstrates a much more complex implementation that brings each of these concepts into play.

// Prepare the feed data and layout.
$titleTemplate = '{actor} got a new <a href="{url}">{game}</a> highscore!';
$titleData = json_encode(array(
	'game' => 'Tetris',
	'url'  => 'http://apps.facebook.com/games/tetris.php',
));
$bodyTemplate = 'Think you can beat {actor}\'s high score<fb:if-multiple-actors>s</fb:if-multiple-actors>? <a href="{url}">Play now!</a>';
$bodyData = json_encode(array(
	'url'  => 'http://apps.facebook.com/games/tetris.php',
));
$bodyGeneral = '<fb:name uid="'.$user.'" useyou="false"/> got a high score of 50!';
$imgSrc = 'http://ecx.images-amazon.com/images/I/31aFXt9OV2L.jpg';
$imgLink = 'http://apps.facebook.com/games/tetris.php';

// Perform the API method call.
$facebook->api_client->feed_publishTemplatizedAction(
	$titleTemplate, $titleData, $bodyTemplate, $bodyData, $bodyGeneral,
	$imgSrc, $imgLink);

A representation of what the above code produces in the News Feed can be seen below.

Templatized Action Example

Understanding Aggregation

Now that that’s clear, let’s get back to the topic of aggregation. To benefit from aggregation and increase the odds of stories reaching users’ News Feeds, understanding Facebook’s aggregation process is vital. Take note of the following two points from the feed.publishTemplatizedAction wiki page.

In order for two stories to be aggregated together, the title_template and body_template markup strings must be identical, the target_ids must be the same, and the associative arrays given by title_data and body_data must also contain identical keys and values. (These pieces of data used to generate a unique identifier for this particular story. This includes strings within <fb:if-multiple-actors> tags — all the strings must be identical.)

Let’s assume that your application allows users to add various items to a custom favorites list. Upon adding, the following pieces of information are used.

// Prepare the feed data and layout.
$titleTemplate = '{actor} added {item} to their favorites!';
$titleData = json_encode(array(
	'item' => $_POST['item'],
));

// Perform the API method call.
$facebook->api_client->feed_publishTemplatizedAction(
	$titleTemplate, $titleData, '', '', '');

If two users — Daniel Negreanu and Huck Seed — add the item “Poker Cards” to their favorites, then assuming someone has befriended both of these users, the two actions would be aggregated into a single story reading “Daniel Negreanu and Huck Seed added Poker Cards to their favorites!”

Alternatively, if Daniel Negreanu adds “Poker Cards” to his favorites and Huck Seed added “Poker Chips” to his favorites, the two stories would not be aggregated. The reason for not aggregating is because the two pieces of data included in the template (the “item” variable) are not the same. Instead, two stories — one for each action — would be generated.

As a developer, your goal is to produce templatized feeds that are highly aggregative. Avoid template variables that are very specific or unique to any given user; those pieces of information should instead appear within the body_general parameter.

Publicizing User Actions

Located within My Applications screen of the developer application, there exists a link labeled “Feed Templates” for each application you have created. Clicking this link followed by the “Register New Template” link leads to a screen similar to the one below.

Register Feed Templates

For each feed published by your application, simply copy and paste the title template and body template into the respective fields found in the Feed Templates form. Before submitting the feed template, be sure to check the box labeled “Show stories of this template to users who have not added this application.” Now, any time an application user performs an action that results in a news feed story being published, any one of his or her friends can potentially read the published story!

Share on Facebook      Share This

Comments

64 Responses to “How to Successfully Publish Widespread News Feed Stories”

  1. Luke Noel-Storr on January 21st, 2008 2:44 pm

    When you start using templated actions, you may come across some issues. Some of these things shouldn’t be issues in my opinion, and so I’ll talk you through them, and encourage you to vote to get them fixed.

    The first issue is due to the limitations involved in aggregation - that the body_template, body_data, title_template, title_data and target must be the same for stories to aggregate. This makes absolute sense; however, the comparisons are done regardless of whether the data would show in an aggregated story or not. Basically, any data included in the <fb:else> section of an <fb:if-multiple-actors> tag would be dropped when stories were aggregated; however, for the stories to aggregate, they still need to be the same. If you agree that this is a nonsense, then please vote for this bug:

    http://bugs.developers.facebook.com/show_bug.cgi?id=668

    Without this being fixed, title_templates and body_templates are becoming very generic, with no specifics to what a particular user has done. This devalues the feed in my opinion. If you could give different versions which would be shown before and after aggregation (by using the <fb:if-multiple-actors> tag), then you could give more specific information in the title that would be shown before aggregation (so on a users mini-feed).

    The next issue is that templates allow you to use the <fb:pronoun> tag. But that’s a good thing right? - well, it is until you try and use it. Once you do try and use it you come across two stumbling blocks. They both relate to the fact that <fb:pronoun> requires a uid attribute to be passed to it. You can’t use a uid directly in the tag, as then you can’t register a template. What you can do is move it to the data parameter instead, but then the data will be different for different users, and so aggregation won’t happen. A simple solution to this would be to have an {actor_id} variable provided in the same way that {actor} is. To see this happen, please vote for this bug:

    http://bugs.developers.facebook.com/show_bug.cgi?id=646

    Fixing bug 668 would also provide a workaround for this bug, so if you only have limited votes not currently allocated (and you don’t want to re-allocate any), then please vote for bug 668 in favour of bug 646.

    The next issue is that testing templated actions is a real pain. Even if your app is in developer only mode, or only test users are accessing it, you can only publish a certain number of stories in 48 hours. This means that if you don’t get a story right in the limited attempts you get, you either have to create another test user, or wait 48 hours. There is a test console, but this can only be used to test potential values, and is not practical to use for real testing. If you think apps in developer only mode and/or test accounts should have the limits removed, then please vote for this bug:

    http://bugs.developers.facebook.com/show_bug.cgi?id=397

    Finally, aggregated stories get “updated” when a new feed is added in to the aggregation, it seems though that the body_general that is shown is always the oldest. It would make more sense for it always to be the newest though, so when it said it was updated, there would be more updated in what was shown to a user. If you agree that the current behaviour seems wrong, please vote for this bug:

    http://bugs.developers.facebook.com/show_bug.cgi?id=1168

    (I don’t actually know if this issue is still “live” as I’ve not seen any aggregated stories for a while).

    On a different note, Matt mentioned aggregation as the reason to use templatized actions. Two other reasons are:

    1) The old method will be deprecated at some point in the future
    2) At some point we should get some stats about the performance of different templates

    Also, you know those thumbs up and ‘x’s you see in your newsfeed? I’m pretty sure they feedback to something that references your templates. This may or may not be a good thing.

  2. Jim Jones on January 21st, 2008 3:54 pm

    I really wish there were some stats in place so that I could verify that my templates are working and are viewable by non-subscribers.

    Stats are gravely needed for testing purposes.

  3. Todd Lucas on January 22nd, 2008 12:18 pm

    Excellent writeup. Thanks.

  4. Eran on January 23rd, 2008 4:46 am

    “As a developer, your goal is to produce templatized feeds that are highly aggregative. Avoid template variables that are very specific or unique to any given user; those pieces of information should instead appear within the data_general parameter.”

    This is the first and only place I’ve seen a “data_general” parameter referenced. I assume that it provides data for the “body_general” parameter. Does this parameter work? If so, is there any documentation on Facebook (or elsewhere)? Otherwise, has anyone actually tried it out?

    Thanks,
    Eran

  5. Matt Huggins on January 23rd, 2008 11:47 am

    Hi Eran. My mistake, that should have read “body_general”, not “data_general”. I have corrected the article.

  6. Matt Huggins on January 23rd, 2008 12:31 pm

    To help others better understand how to successfully aggregate their stories, the following is an email I received demonstrating the best practice for an example scenario. The question reads the following:

    Do you know of a way to get action specific data for an aggregated feed item? For instance, can I have an item that says “Matt has recommended Something Happened by Joseph Heller on BookRecommenderApp”, or “Eran has recommended Under the Banner of Heaven by Jon Krakauer on BookRecommenderApp”. But if the two show up around the same time they get aggregated into: “Eran and Matt have recommended books on BookRecommenderApp.”

    And here is my response:

    From the wiki: “…the associative arrays given by title_data and body_data must also contain identical keys and values.” This means that you will not be able to do what you’re hoping, though it would be nice if something like that were possible. Your best bet is to do something like this:

    $user = new Facebook(...);
    $title = 'Under the Banner of Heaven';
    $author = 'Jon Krakauer';
    
    $body_template = "{actor} <fb:if-multiple-actors>have recommended books<fb:else>has recommended a book</fb:else></fb:if-multiple-actors> on BookRecommenderApp.";
    $body_general = "<fb:name uid='{$user}' useyou='false' firstnameonly='true'/> recommends {$title} by {$author}.";
    // publish feed here.

    By putting data that won’t aggregate into body_general, you’re allowing stories to otherwise aggregate.

  7. Robert Turrall on January 24th, 2008 5:29 am

    Very nice write-up Matt. Thank you!

    I’ve noticed that I could get the templated feeds working perfectly second attempt in one case, first attempt in another but then not at all in a third case - even when using the same basic code… templated feeds really are *fun* to work with.

    I’ll be taking your tetris example from the article and taking another pass at my reluctant feed.

    Oh, by the way: I’ve seen more than 10 feeds produced within a couple of hours from repeatedly testing one app (not in developer mode) so wonder if there is another Facebook “feature” at work here too….

    Regards
    Robert

  8. Matt Huggins on January 24th, 2008 10:44 am

    Thanks for sharing Robert! When in doubt, you can always test feed data in the Feed Preview Console. Also, although I did not include it in this article, it would be good practice to track the return values of this API call. (The specific range of return values can be seen on the wiki page.)

    One thing to note is that, at least from my own experience, the return values seem to be encased in an array instead of simply being an integer as expected. Here’s an example implementation that shows how to retrieve the value, though you may need to tweak it to your needs.

    $response = $facebook->api_client->feed_publishTemplatizedAction(...);
    if (!is_array($response) || $response[0] !== 1) {
        // Error!  Check the error codes on the wiki.
    }
  9. Montoya on January 27th, 2008 11:52 pm

    I just wanted to say that this article is a perfect guide to feed stories and is way more informative than the stupid wiki in the Facebook documentation. Thanks for writing it!

  10. Omar Ali on January 29th, 2008 5:56 am

    Hi

    Thank you for your tutorials, I’ve learned a lot from reading them but I can’t seem to get past an error. It’s

    PHP Fatal error: Call to undefined method FacebookRestClient::feed_publishTemplatizedAction() in /site/folder/lib.php on line 266

    I have global $facebook; called in the function and the latest Facebook PHP client Library

    Any Suggestions would be very much appreciated

  11. Matt Huggins on January 30th, 2008 2:29 pm

    Omar — Unfortunately, I can’t tell what the cause of the error is from the error message alone. Would you be able to provide more information, including the call lines leading up to and including where you call feed.publishTemplatizedAction?

  12. Jeff on February 5th, 2008 1:19 am

    Omar - you probably need to get the latest client library - you probably have a client library downloaded prior to the introduction of that method.

  13. Robert Turrall on February 8th, 2008 5:38 am

    Matt,

    I’ve had some problems with getting feeds to work if “custom” data is required in the title_data - a score value, for example. The reason is that the version of PHP on the client’s server does not support json_encode and all attempts at hand-coding the json format seem to have failed. I’ve used php code such as the following:

    $nf_title_template = ‘{actor} scored {score} in XXXXXXXX!’;
    $nf_title_data = ‘{”score”:”‘.number_format($score).’”}’;

    Everything else seems fine, all tests fine in the console but no feeds are displayed. Is there an obvious error in the code above for the title_data array?

    Any tips would be great.

    Thanks

    Robert

  14. Robert Turrall on February 8th, 2008 5:39 am

    ps. I’ve tried it without the number_format() too - no difference ;-)

  15. Matt Huggins on February 8th, 2008 2:51 pm

    Hi Robert — Do you have a sample of the actual call you make to feed.publishTemplatizedAction? Did you try checking what the response value is? (Check out my comment above from January 24th, 2008 10:44 am.) Do you have the latest client API?

  16. Robert Turrall on February 10th, 2008 4:33 pm

    Hi Matt,

    Yes, here’s the code used (anonymised):

    $nf_actor_id = $user;
    $nf_title_template = '{actor} scored {score} !';
    $nf_title_data = '{"score":"'.$score.'"}';
    
    $nf_body_template = '<b>{actor} just played with a final score of {score}.</b>';
    $nf_body_data = '{"score\":"'.$score.'"}';
    
    $nf_body_general = '<a href="http://apps.facebook.com/xxxxxxx/">Play now to see if you can beat my score!</a>';
    $nf_image_1 = 'http://www.valid url';
    $nf_image_1_link = 'http://apps.facebook.com/xxxxxx/index.php';
    
    $feed = $facebook->api_client->feed_publishTemplatizedAction($nf_actor_id, $nf_title_template, $nf_title_data, $nf_body_template, $nf_body_data, $nf_body_general, $nf_image_1, $nf_image_1_link);

    As the app is live I’m not going to play around with the code but I’m setting up a test copy to trace out any exceptions…

    Any obvious issues with the above?

    Thanks
    Robert

  17. Robert Turrall on February 10th, 2008 5:25 pm

    ps. All traced out. No exception caught, no feed.

  18. Matt Huggins on February 11th, 2008 7:08 pm

    Robert - The main thing that stands out to me in your code is this line.

    $nf_body_data = '{"score\":"'.$score.'"}';

    It appears that you have a backslash (\) in there that you don’t need. Try changing your line to this:

    $nf_body_data = '{"score":"'.$score.'"}';

    Hopefully that helps. Also, are these actions publishing to the user’s Mini-Feed at all?

  19. Robert Turrall on February 12th, 2008 4:39 pm

    Thanks for pointing out the little error in the code Matt. Guess what? It makes no difference…. totally wierd. No mini feed, no news feed. I’m beginning to wonder how to get “custom” data other than {actor} adn {target} into the title or body templates…

  20. Dan Kamins on February 19th, 2008 9:47 pm

    Matt,
    Great tutorial! Hope you write some more just like it.

  21. Sreedevi on February 21st, 2008 2:48 am

    Hi,

    I have some problem while creating minifeed.

    getting these errors.

    1.exception ‘FacebookRestClientException’ with message ‘Feed action request limit reached’
    2.illegal attr “{” in tag “”. Attribute names can only contain alphanumeric characters, underscores, and hyphens. like these

    I cant figure out what error was.? Could you please help me?

    My code is here………

    <?php try {
        global $user;
        $friendid=689157058;
        $details="hai to all";
        $target =689157058;
        // Prepare the feed data and layout.
        $titleTemplate = "{actor} and  agreed to the following xxxx!";
        $titleData = json_encode(array( 'indexurl'  => 'http://apps.facebook.com/XXXXXX/index.php' ));
    
        $bodyTemplate = '{details} <a href="{url}">See More</a>';
        $bodyData = json_encode(array( 'url'  => 'http://apps.facebook.com/XXXXXX/xxxx_accepted.php','details' =>'Detail : '.$details.'...', 'url2' =>'http://apps.facebook.com/XXXXXX/index.php', 'url3'  =>'http://apps.facebook.com/XXXXXX/friends_xxxx.php'));
    
        $bodyGeneral = '<a href="{url2}">Offer a New Xxxx</a> | <a href="{url3}">See Your Friends Xxxxs</a>';
        $imgSrc = 'http://www.XXXXXX.com/facebook/images/profile_page.gif';
        $imgLink = 'http://apps.facebook.com/XXXXXX/index.php';
    
        // Perform the API method call.
        $feed=$facebook->api_client->feed_publishTemplatizedAction( $user,
        $titleTemplate, $titleData, $bodyTemplate, $bodyData, $bodyGeneral,
            $imgSrc, $imgLink,'','','','','','',$target); 
    
    } catch (Exception $e) {
        error_log($e);
        echo $e;
    }?>

    thanks in advance

  22. Matt Huggins on February 22nd, 2008 12:43 am

    Sreedevi - You are only allowed to publish a certain number of feed items per day, depending on what threshold bucket your application falls within. Unfortunately, this can interfere with testing an app, but this would explain why you are receiving the “Feed action request limit reached” error message.

    I don’t see anything that stands out as to why you are receiving the “illegal attr ‘{’ in tag ”” message. Your JSON variable names are all alpha-numeric, and there isn’t anything else that appears to be inherently wrong at first look. Is there any additional information you’re being provided in this error message?

  23. Pooja on February 25th, 2008 1:29 am

    Matt,
    I am trying hard for last couple of days to publish this sample feed but no luck. I have included this code in one of the exsiting php page and code runs without any error but there is no new item in mini-feed. I was wondering if there is any other setting that I need to update? Your help is greatly appreciated.

    // Prepare the feed data and layout.
    $titleTemplate = '{actor} hit {target} with {item}!';
    $titleData = json_encode(array(
        'item' => 'a water balloon',
    ));
    $target = $_POST['target_id'];
    
    // Perform the API method call.
    $facebook->api_client->feed_publishTemplatizedAction(
        $titleTemplate, $titleData, '', '', '',
        null, null, null, null, null, null, null, null,
        $target);

    Thanks,
    Pooja

  24. Matt Huggins on February 25th, 2008 3:06 pm

    Pooja — a few questions:

    • What is the value of $target in your code? Is it a valid UID? Is it a friend of the current user?
    • Have you added the application to your profile? Facebook won’t publish to your Mini-Feed/News Feed if you haven’t first added the application.
  25. Adam Cox on February 25th, 2008 3:37 pm

    Very well written article!

  26. Pooja on February 25th, 2008 5:31 pm

    Matt,
    I am using hardcoded id of my friend in facebook.

    $target = ‘8306861**’;

    I have removed last two digits with * for obvious reasons.

    Both me an my friend has added this application to their profile.

    May be following info wil give you some clue.
    1. I haven’t published this application yet as I am still developing it.
    2 This code executes when the index.php of the application loads in the facebook.
    3. I have registered this feed as follows
    Title Template: {actor} hit {target} with {item}!
    Body Template: json_encode(array(’item’ => ‘a water balloon’))

    Thanks for your help,

    Pooja

  27. Matt Huggins on February 25th, 2008 6:52 pm

    Pooja, check out my comment above from January 24th, 2008 10:44 am. Try checking the return value of your call to feed.publishTemplatizedAction and comparing it to the return values shown in the wiki page.

  28. Pooja on February 25th, 2008 10:17 pm

    Matt,
    I tried to get the response data but it looks like it is not returning anything. I really don’t know what wrong I am doing.

    $return=$facebook->api_client->feed_publishTemplatizedAction($titleTemplate,$titleData, '', '', '');

    I tried to get return values using echo but it only prints return=retrun0return1=
    echo ‘return=’.$return;
    echo ‘return0=’.$return[0];
    echo ‘return1=’.$return[1];

    Thanks,
    Pooja

  29. Matt Huggins on February 25th, 2008 11:12 pm

    Pooja, based upon the response code, error code 0 means there is a permissions error. This typically means you’re attempting to write a feed story for someone who has not added the application. If you have added the app to your profile, I honestly don’t know what the issue is.

  30. Matt Parkins on February 25th, 2008 11:41 pm

    Great tutorial - thanks!

  31. Tyler on February 27th, 2008 1:21 pm

    Have you ever encountered a problem where the feed code causes an error for a small percentage of users? For me it’s about 5-15% or so near as I can tell and I haven’t been able to recreate the bug on my test accounts so far. My feed code is pretty much a carbon copy of this tutorial with variables added/changed for my purposes.

    One thought I had.. does facebook automatically deal with it properly if you send more feed items then allowed in the allotted time? It doesn’t make sense based on what I’ve seen but I’m quite stumped.
    Thanks for any ideas anyone has

  32. Jaime Cham on March 5th, 2008 8:10 am

    What is the point of putting things inside the *_data sections? feeds are not aggregated based on it and they must be identical for aggregation to happen, so one might as well just inline them onself. Or am I missing something here?

    Also the same for the target_id. Or is there some higher likelihood of a feed being shown to the target_ids or their friends?

    Thanks for any ideas!

  33. Matt Huggins on March 5th, 2008 12:57 pm

    Let’s say you have a situation where 2 people submit a review for Final Fantasy, and one person reviews Super Mario. If you have a body_template like this…

    {actor} submitted a review for {title}!

    …then you’ll have the chance of aggregating two stories, one about Mario, and one about Final Fantasy. But you could still use the body_general to share the exact review description entered by the user, since that will essentially never be the same from one user to the next, and thus never aggregate.

    Furthermore, if you had data that varied from story to story, and you were not to take advantage of the *_data parameters, then you would have to register each and every possible feed template with Facebook in order for it to aggregate to non-app users.

  34. Ankit on March 10th, 2008 4:55 am
    $titleTemplate = '{actor} hit {target} with {item}!';
    $titleData = json_encode(array(
        'item' => 'a water balloon',
    ));
    //$target = $_POST['target_id'];
    
    // Perform the API method call.
    $facebook->api_client->feed_publishTemplatizedAction(
        $titleTemplate, $titleData, '', '', '',
        null, null, null, null, null, null, null, null,
        null);

    i am using this code it’s getting error like:Fatal error: Uncaught exception ‘FacebookRestClientException’ with message ‘Feed action request limit reached’ in /backup/project/public_html/social/album/facebook-platform/client/facebookapi_php5_restlib.php:1520 Stack trace: #0 /backup/project/public_html/social/album/facebook-platform/client/facebookapi_php5_restlib.php(295): FacebookRestClient->call_method(’facebook.feed.p…’, Array) #1 /backup/project/public_html/social/album/index.php(66): FacebookRestClient->feed_publishTemplatizedAction(’{actor} hit {ta…’, ‘{”item”:”a wate…’, ”, ”, ”, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) #2 {main} thrown in /backup/project/public_html/social/album/facebook-platform/client/facebookapi_php5_restlib.php on line 1520
    what is my mistake can u tell me??????????

  35. Matt Huggins on March 10th, 2008 2:31 pm

    Ankit - This occurs when you have reached the maximum allowed number of feed actions per user being created in any given day. This exception can basically be ignored from the standpoint of a developer, as there is nothing you can do to work around it. You just have to wait until the next day for the feed limit to reset for each user in order for the code to start “working” again.

  36. cicco on March 14th, 2008 7:43 am

    Hi Matt,
    please help me, i’m stuck..

    my script always got error:
    Fatal error: Uncaught exception ‘FacebookRestClientException’ with message ‘Feed story title_data argument was not a valid JSON-encoded array’ in …

    finally, i try very simple code like this:

    $facebook->api_client->feed_publishTemplatizedAction($user,”{actor} is testing around”,NULL,NULL,NULL,NULL);

    but still get same error..

    i don’t know whats wrong…
    please help me how to fix this error.

    i use PHP ver. 5.2.4

  37. Linda on March 18th, 2008 3:13 pm

    I don’t understand where the code is supposed to go? Is it in my index.php or in my feed_handler. Sorry for the dumb question.

    Linda

  38. Matt Huggins on March 18th, 2008 5:29 pm

    cicco - try changing your NULL’s to empty strings.

    Linda - The code goes wherever you want it to create a news feed story. If you put it on your index.php, it’ll end up create a feed action any time someone accesses your application’s index page (unless you put it within a conditional statement, of course). If you want a feed story to be created only when a user accesses some other page or performs some other action within your app, then place the code there instead (or in addition).

  39. cicco on March 19th, 2008 6:56 am

    matt, i will try everything, with empty string, with json array in title_data, etc.. but still got same error ‘Feed story title_data argument was not a valid JSON-encoded array’
    i dont know what wrong..
    in my phpinfo: json support enabled , json version 1.2.1
    maybe more setup in my php.ini or something else?

    any idea matt?

    i ask this problem to forum too
    http://forum.developers.facebook.com/viewtopic.php?pid=55940

  40. Rick Troberman on March 21st, 2008 11:48 am

    Matt,

    I’m doing a search for Bungee Labs for a Director of Developer Learning. The role is all about leading a team tasked with creating learning content for the Bungee developer community.

    Bungee has raised $25M in the last year and may be the best funded development envioronment startup in recent history. They are a very cool company.

    If you might be interested in discussing the role let me know.

    Rick

  41. T.Mayilrajan on March 22nd, 2008 4:34 am

    Hi Matt,
    how to publish feed using asp.net
    please help me

    T.Mailrajan

  42. Oops… I think I just blogged » Blog Archive » What I Learnt Today - My First Facebook Application on March 22nd, 2008 6:28 am

    […] to building a Facebook Application A general overview and FAQ for creating a Facebook Application How to successfully publish news and mini-feed stories Converting PHP4 associative arrays into JSON […]

  43. Oops… I think I just blogged on March 22nd, 2008 6:32 am

    […] to building a Facebook Application A general overview and FAQ for creating a Facebook Application How to successfully publish news and mini-feed stories Converting PHP4 associative arrays into JSON […]

  44. Kitson on March 27th, 2008 2:00 pm

    Great tutorial, thx.

    But it still not help. I get no feed after running the code:

    $titleTemplate = ‘{actor} date with {target}’;
    $titleData = ”;
    $bodyTemplate = ”;
    $bodyData = ”;
    $target_ids = “7337191**”;
    $rs = $facebook->api_client->feed_publishTemplatizedAction(
    $titleTemplate, $titleData, $bodyTemplate, $bodyData, ”,
    ”, ”,”, ”,”, ”,”, ”,
    $target_ids, ”);
    echo “feed send2: [”.$rs.”] “;

    Simple enough? But still no feed, and it echo out “feed send2: [] “, no return value, not 0, not 1.

    As I find some of you get the same problem, I wonder if it’s related to the PHP setting? is any PHP function need to be granted to use it? Please if anyone has any idea, thanks.

    Besides, I also want to know what if I don’t register my feed? I will not be able to send? (I did registered, just wonder)

    That’s all I want to ask, thanks~

  45. steve on March 31st, 2008 5:42 am

    Great article, thanks.

    Three questions:-

    1. How do we find out what the daily limit is for users feeds? Does it fall into one of the Allocation buckets and which one (Notifications or requests)?

    2. Is there anyway of surpressing the automatic userStatus change mini-feed - we want to enable mini-feed for all our users and only update the users Status for users who opt in to have their status updated. This results in duplicate mini-feed items.

    3. When will the templatized action stats be available?

    Thanks

  46. Trung Hieu on April 3rd, 2008 6:17 am

    when using feed_publishTemplatizedAction. do it has show in New Feeds friends who have not added application?
    thanks.

  47. Omer on April 4th, 2008 4:54 am

    I have read all replies on this page , but still not able to make that function work

    i havent submitted by app to the facebook store , could that be an error

    the function is returning a zero in a an arry ,

    can any one help me out

    Omer

  48. bortuzar on April 9th, 2008 7:52 pm

    Omer, I also got a returning a zero in a an array . Solution is to add the app to your facebook account. Since you are a developer you can see the app, but it doesnt mean you have added it. hope it helps.

  49. Oleg on April 11th, 2008 5:46 pm

    I created an application to be able to publishTemplatizedAction(in c# to be able to publich feeds you need to have application id), on my website I have users that might have facebook accounts, if that’s the case is there a way to send my users/friends feeds to their facebook account?

  50. JDJaramillo on April 11th, 2008 8:01 pm

    Hi there,
    I was trying to folow this tutorial, and it’s very cool and simple, but there’s something you’re missing and it took me a long time to find out what was wrong.
    when you do the call $facebook->api_client->feed_publishTemplatizedAction( $titleTemplate, $titleData, $bodyTemplate, $bodyData, $bodyGeneral, $imgSrc, $imgLink); you are missing the most important parameter, which is the user’s ID… so it should be something like this: $facebook->api_client->feed_publishTemplatizedAction($uid, $titleTemplate, $titleData, $bodyTemplate, $bodyData, $bodyGeneral, $imgSrc, $imgLink);

    At least it didn’t work for me until I did that.

  51. Matt Huggins on April 11th, 2008 9:11 pm

    JDJaramillo - Your comment is incorrect. The method you are using is for old versions of the API client. However, it has since been deprecated (shortly before this article was published). I highly recommend you download the updated API client to ensure your application is interacting with the Facebook Platform servers in the most optimal methods.

  52. Hendre on April 18th, 2008 4:04 pm

    Does anyone know how to add multiple lines to a news feed. It seems that tags are being thrown away.

  53. links for 2008-04-24 on April 23rd, 2008 8:43 pm

    […] How to Successfully Publish Widespread News Feed Stories : Facebook Developer Since the availability of the Facebook Platform’s feed.publishTemplatizedAction API call, developers have had the opportunity for stories to be shared with friends who have not yet installed their application. (tags: facebook development api howto) […]

  54. David on April 25th, 2008 7:52 am

    Great tutorial - had it up and running in no time, thanks :)

    I have a problem overcoming the 10 story limit, though. I want to create an app that will publish news stories to user’s friends via the newsfeed but without the owner of the app having to be logged in.

    The 10 story limit is a limit on the logged in user (the one running the app) - is there any other way to publish to newsfeeds?

    Thanks again for the simple tutorial.

  55. Ian on May 6th, 2008 9:28 am

    Hey Matt,

    Great tutorial. Like many others, I’m not having much success getting the story to show up on the news feed for friends. I’m getting an array back with the error of 1 (unknown error). Below is my code (APP_URL is a PHP constant for the URL of the app). It updates the mini-news feed no problem on the user profile page, but does not show up in news feeds of test accounts (they have nothing else getting pushed to it).

    $titleTemplate = ‘{actor} took the {title}‘;
    // Prepare the feed data and layout.
    $titleData = json_encode(array(
    ‘url’ => APP_URL,
    ‘title’=>” Quiz”
    ));
    $bodyTemplate = ‘Want to see what type you are? {title}‘;
    $bodyData = json_encode(array(
    ‘url’ => APP_URL,
    ‘title’=>”Take the Quiz”
    ));
    $bodyGeneral = ‘ got a score of 50!’;
    $imgSrc =null;
    $imgLink = null;

    // Perform the API method call.
    try{ $res=$facebook->api_client->feed_publishTemplatizedAction(
    $titleTemplate, $titleData, $bodyTemplate, $bodyData, $bodyGeneral,
    null, null);
    echo “”;
    print_r($res);
    echo “”;
    }
    catch(Exception $e){die ($e);}

  56. Kevin on May 19th, 2008 1:15 pm

    <?php
    require_once(’facebook.php’);
    $_POST[”public”]=”y”;
    /* initialize the facebook API with your application API Key
    and Secret */
    $facebook = new Facebook(”xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”,”xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”);

    $titleTemplate = ‘{actor} areis I have something to tell you’;
    $titleData = json_encode(array(
    ‘game’ => ‘I have something to tell you’,
    ‘url’ => ‘http://apps.facebook.com/mymyngle/index.php’,
    ));
    $bodyTemplate = “I have something to tell you click here to view details“;
    $bodyData = json_encode(array(
    ‘url’ => ‘http://apps.facebook.com/mymyngle/index.php’,
    ));
    $bodyGeneral = ”;
    $imgSrc = ‘http://mysite.com/flirtnew/heartfb.jpg’;
    $imgLink = ‘http://myngle.wiantech.com/images/mood_1.jpg’;
    $target_ids=14486701??;
    // Perform the API method call.
    $facebook->api_client->feed_publishTemplatizedAction($titleTemplate, $titleData, $bodyTemplate, $bodyData, $bodyGeneral, $imgSrc, $imgLink);
    if($_POST[”public”]==’y')
    {

    try {

    $facebook->api_client->feed_publishTemplatizedAction($titleTemplate, $titleData, $bodyTemplate, $bodyData, $bodyGeneral, $imgSrc, $imgLink,$target_ids);
    } catch (Exception $e) {
    echo ‘Caught exception: ‘, $e->getMessage(), “\n”;
    }

    }

    ?>

    When I run this code I get an error about the picture id being wrong. However when I remove the $_POST[”public”]=”y”; and run the first section which is minus the target_ids it works ok. What am I doing wrong I want to be able to send this code to all friends not just the logged on user?

    Thanks

  57. HoofSC on June 14th, 2008 9:53 pm

    Matt,

    Having a major fault error problem. Are variables valid in the json_encode, and if I’m running php 5, do I have to do anything else to get the json_encode to work?

    Here’s the error:
    Fatal error: Uncaught exception ‘FacebookRestClientException’ with message ‘Invalid parameter’ in /home/usr/public_html/f8/callback/facebookapi_php5_restlib.php:1628 Stack trace: #0 /home/usr/public_html/f8/callback/facebookapi_php5_restlib.php(327): FacebookRestClient->call_method(’facebook.feed.p…’, Array) #1 /home/usr/public_html/f8/callback/sendRequest.php(61): FacebookRestClient->feed_publishTemplatizedAction(’{actor} has sen…’, ‘{”url”:”http:\/…’, ‘<a href=”sendwi…’, ”, ”, ”, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, Array) #2 {main} thrown in /home/usr/public_html/f8/callback/facebookapi_php5_restlib.php on line 1628

    My information is coming from a form, and here is Here is sendRequest.php:

    ————————————————-

    <?php
    require_once ‘appinclude.php’;
    require_once ‘dbconfig.php’;

    $actorid = $_REQUEST[’actorid’];

    $batteryid = $_REQUEST[’batteryoption’];

    $targetids = $_REQUEST[”ids”]; //an array of selected uid’s

    foreach ($targetids as $targetid) { //for each friend selected

    echo ‘You have sent a basket of battery number ‘ . $batteryid . ‘ to ‘;

    //make a record of gift in database

    }

    //get the sent battery info
    $result = mysql_query(”SELECT * from tbl_batteries WHERE battery_id = ‘” . $batteryid . “‘”);
    while ($row=mysql_fetch_array($result)) {
    $batteryimagepath = $row[”imagepath”];
    $batteryname = $row[”name”];
    $year = $row[’year’];
    $batteryRating = $row[’rating’];
    }

    //prepare the templatized feed data and layout

    $titleTemplate = ‘{actor} has sent {target} a basket of <a href=”{url}”>{batterytype} - {year} </a> using the <a href=”http://apps.facebook.com/batteriesapp”>Batteries</a> application.’;

    $titleData = json_encode(array(
    ‘url’ => ‘http://apps.facebook.com/batteriesapp/battery.php?type=’ . $batteryid,
    ‘batterytype’ => $batteryname,
    ‘year’ => $year,
    ));

    $bodyTemplate = ‘

    {batteryimage}

    <a href=”{url}”>{batteryname} {year}</a>
    {batteryRating}

    ‘;

    $bodyData = json_encode(array(
    ‘batteryimage’ => ”,
    ‘url’ => ‘http://apps.facebook.com/batteryapp/battery.php?type=’ . $batteryid,
    ‘batteryname’ => $batteryname,
    ‘year’ => $year
    ‘batteryRating’ => ‘Avg Rating: ‘ . $batteryRating,
    ));

    //perform the API method call
    $facebook->api_client->feed_publishTemplatizedAction(
    $titleTemplate, $titleData, $bodyTemplate, $bodyData,”,”,
    null, null, null, null, null, null, null, null,
    $targetids);

    —————————————-

    Is there something horribly wrong in my code?

    N00b,
    HoofSC

  58. HoofSC on June 14th, 2008 9:56 pm

    oops

    my code didnt go through as planned with unescaped html. any help would be greatly appreciated!

  59. daniel on June 18th, 2008 6:46 pm

    I’m having trouble getting publishTemplatizedAction to show in my mini-feed:

    Thanks to your tutorial, I’m able to pass all the parameters correctly, but I still get the permissions error returned.

    I saw that you have told other people to “add” their app? Do you mean use require_add()? Add to the directory?

    My app only uses require_login() , it’s not published in the directory, and dev mode is off.

    I’ve documented my problem in the forum:
    http://forum.developers.facebook.com/viewtopic.php?id=15995

    Would greatly appreciate your help!!

  60. Daniel Nørby Andersen on June 21st, 2008 4:38 am

    I’m currently writing my very first FaceBook app (see website) and what a thrill.

    I’ve cheated a wee bit. I’ve made one user (the dude who made and hosts the application) and another user to test the app. Snatched some code from this page (studied it hardcore), and before I knew it I’d made my first Mini-feed. Yay!

    Now the question: How long will it take the feed to hit my ‘friend’’s News Feed? Should it hit him instantly or does it usually take an hour+? Have i made an error or will i have to wait and see? Have I misunderstood the concept completely? :)

  61. Stefano Corti on July 8th, 2008 11:09 am

    Just a curiosity… we are building a facebook app for our site. and here is what we wanted to do:
    when a facebook users, navigating our website (not facebook of course) and performs certain actions, we want to send the feed update to his/hers profile.
    So, is it possibile to send feeds from our website, and not thru the facebook application?

  62. Ajay on July 17th, 2008 6:52 am

    We are trying to add feed to our application. Took help from your article. It worked in first go. Many Thanks for wonderful article.

    After some days not when I try to run the same feed application it gives

    Errors while loading page from application
    Received HTTP error code 500 while loading

    I have basically used the simple example you have given. Below is the code.
    $titleTemplate = ‘{actor} added {item} to their favorites!’;
    $titleData = json_encode(array(’item’ => ‘HI’ ));
    // Perform the API method call.
    $response= $facebook->api_client->feed_publishTemplatizedAction(
    $titleTemplate, $titleData, ”, ”, ”);
    When I comment the last statement the code runs fine but obviously no feed.

    Many thanks for help
    Ajay

  63. jishu on August 6th, 2008 3:32 pm

    $titleTemplate = ‘{actor} got a new <a href=”{url}”>{game}</a> highscore!’;
    $titleData = json_encode(array(’game’ => ‘Tetris’, ‘url’ => ‘http://apps.facebook.com/games/tetris.php’));

    $titleTemplate = ‘{actor} got a new <a href=”{url}”>{game}</a> highscore!’;
    $bodyData = json_encode(array(’game’ => ‘Tetris’, ‘url’ => ‘http://apps.facebook.com/games/tetris.php’));

    $bodyGeneral = ‘ got a high score of 50!’;
    $imgSrc = ‘http://www.topgunmma.com/facebook/images/search.gif’;
    $imgLink = ‘http://apps.facebook.com/games/tetris.php’;

    // Perform the API method call.
    $facebook->api_client->feed_publishTemplatizedAction(
    $titleTemplate, $titleData, $bodyTemplate, $bodyData, $bodyGeneral,
    $imgSrc, $imgLink);

    This code is giving this error :
    ‘Feed story body_data argument was not a valid JSON-encoded array’

    can anybody help , please

  64. Matt Huggins on August 7th, 2008 1:36 pm

    @jishu - It looks like you’re defining $titleTemplate twice. Try renaming the second one to $bodyTemplate to see if that helps.

Got something to say?





Close
E-mail It