Facebook Cookbook - Jay Goldman [145]
Registering your templates is just the first step. This Discussion will give you a quick tour of the other Feed API calls related to template bundles, as well as an example of what the stories look like.
Feed story example: Causes
Figures 9-8, 9-9, and 9-10 show examples of the three different story sizes from the Causes app.
Figure 9-8. Causes one-line story
Figure 9-9. Causes short story
Figure 9-10. Causes full story
The “Add Comment” links are added by Facebook automatically.
About tokens
You can create as many tokens as you’d like in your feeds by defining them on the fly (anything wrapped with {* and *} automatically becomes a token). The only limitation on naming is that you can’t conflict with one of the special tokens outlined later in this section.
There are two special tokens that you can include in your templates and don’t need to define:
{*actor*}
The user who originated the action that resulted in the story being published.
{*target*}
A list of the friends of the actor on whom or with whom the actor performed the action. The advantage to using this token over a custom one (e.g., {*friends*} or something similar) is that Facebook will automatically output the right text for the number of included targets (one friend just lists the name, two adds “and”, three turns into a list ending in “and”, etc.).
In both cases, Facebook will worry about substituting the right people into the story for you. In addition to those two tokens, you can also take advantage of a collection of additional templates that Facebook will handle for you. You can use exactly one of the following four tags in each story:
{*images*}
You can include up to four images in your story, so when you publish a story using Feed.publishUserAction(), this token should map to an array containing four records, with required src keys and optional href keys if you’d like the images to be links.
{*flash*}
You can include a single Flash movie that fits into a box measuring 100 pixels high by 130 pixels wide. When you publish a story using Feed.publishUserAction(), this token should map to an array containing a single entry with the required keys swfsrc (the location of the Flash movie) and imgsrc (the location of an image to display until the user clicks to activate). The default size is 30 pixels high by 100 pixels wide, so you’ll need to specify an optional height (an integer between 30 and 100) and width (one of 100, 110, or 130) if you want to override the default.
{*mp3*}
You can include a single MP3 that Facebook will render as playable using its audio controller. You’re required to include an src key (the location of the MP3), and you can include optional title, album, and artist keys (as strings).
{*video*}
You can include a single video that Facebook will make playable in the story. You’re required to include the keys video_src (location of the video) and preview_img (image to display until the user clicks to activate). You can optionally include video_title, video_type (defaults to “application/x-shockwave-flash”), and video_link keys.
Getting all of your templates
Use the Feed.getRegisteredTemplateBundles() method to retrieve all of the template bundles your application has previously registered:
$bundles = $facebook->api_client->feed_getRegisteredTemplateBundles();
You’ll get back an array containing all of the templates, including their IDs for use in subsequent calls.
Getting a template bundle
Use the Feed.getRegisteredTemplateBundleByID() method to retrieve a specific template bundle by ID:
$bundle = $facebook->api_client->feed_getRegisteredTemplateBundleByID(12345);
where 12345 is a valid template bundle ID.
Deactivating a template bundle
If you need to deactivate a template bundle you’ve previously registered, use the Feed.deactivateTemplateBundleByID() method:
$result = $facebook->api_client->feed_deactivateTemplateBundleByID(12345);
where 12345 is a valid template bundle ID. The result will be true if the template was found and deactivated, and false