Building Apps

Page 259

17_277959-ch11.qxp

5/5/08

11:28 AM

Page 243

Chapter 11: Communicating with the News Feed and Notifications {actor} added a new recipe. {actor} is throwing a pie at {target}. {actor} made a cake for {target}.

The one potential gotcha that can arise when stories are aggregated, however, is subject-verb agreement. For example, suppose the following two stories are combined into a single news item: Jordan is throwing pie at Josh. Jared is throwing a pie at Josh.

With the template defined above, the following aggregated title would be generated: Jordan and Jared is throwing a pie at Josh.

To the rescue, the fb:if-multiple-actors allows you to specify alternate content when multiple actors are used in an aggregated story. Here’s how the template would look: {actor} <fb:if-multiple-actors>are<fb:else>is</fb:else></fb:if-multiple-actors> throwing a pie at {target}.

Now, when aggregated, the template displays grammar that would make any English teacher proud: Jordan and Jared are throwing a pie at Josh.

The {actor} and {target} tokens are reserved. The {actor} receives its value from the current session ID (current user) or the $page_actor_id (if the actor is a Facebook Page). The {target} token receives its value from the $target_ids parameter. However, consider the following template: {actor} made a {recipe} for {holiday}.

The {recipe} and {holiday} tokens are variables that I am defining specifically for use with my news story. The $title_data and $body_data parameters are used for passing this data to Facebook. The values for these two parameters must be in the form of a JSON-encoded associative array: {“recipe”:”California Grits”,”holiday”:”Festivus”}

In PHP, you can define using the json_encode() function as $title_data = json_encode(array( ‘recipe’ => ‘California Grits’, ‘holiday’ => ‘Festivus’, ));

243


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.