Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [144]

By Root 724 0
(0) or blank if it can’t.

Getting a (Ref) Handle on FBML


Problem


I want to put some FBML into Facebook’s cache so that I can use it in a whole bunch of user Profiles.

Solution


Use the FBML.setRefHandle() method:

$return = $facebook->api_client->fbml_setRefHandle('myHandle','FBML goes here');

Discussion


This will associate the handle you pass as the first parameter with the FBML content that you pass in the second one. You can then pull this content at any time using the fb:ref FBML tag (see FBML Caching for more info).

This can be used only by web-based Facebook apps. Desktop apps are out of luck on this one.

Three Story Sizes: Working with Template Bundles


Problem


I’d like to be able to publish stories that take advantage of the one-line, short story, and full story formats introduced in the mid-2008 Profile redesign. What do I need to do?

Solution


In addition to splitting Profiles into multiple tabs, the Profile redesign also saw the advent of Feed stories appearing in one-line, short story, and full story formats. As a developer, you need to register “template bundles” with Facebook before you can publish stories in the different formats. Template bundles contain at least one of:

One or more one-line story templates

One or more short story templates

One or more full story templates

You can specify multiple one-line templates by including them in a JSON-formatted array. Remember that order is very important here, and you want to include your most detailed template first and your least detailed last. For example:

{*actor*} just shared a {*nap-type*} with {*target*}.

{*actor*} just shared a nap with {*target*}.

{*actor*} just napped.

Tokens are always in the form {*token_name*}, and subsequent templates should only ever include a subset of the tokens used in the template prior (in other words, your templates should get less and less detailed without introducing new content). See the Discussion for more info about tokens. Facebook will always use the most flexible (i.e., the first) template for Mini-Feed stories, and it will try to aggregate stories together for News Feeds. Keep in mind that your least-specific template (i.e., the last one) has the highest likelihood of being used for aggregation, since it’s the most likely to have content from all of the actors (see the Discussion for more about aggregation). Here’s an example of template registration:

$oneLiners = array('{*actor*} just shared a {*nap-type*} with {*target*}.',

'{*actor*} just shared a nap with {*target*}.', '{*actor*} just napped.');

$shortStories = array(

array('template_title'=>'{*actor*} just shared a {*nap-type*}

with {*target*}', 'template_body'=>'

It was {*status*}!

'),

array('template_title'=>'{*actor*} just shared a nap with

{*target*}','template_body'=>'

It was {*status*}!

'),

array('template_title'=>'{*actor*} just napped.', '

template_body'=>'

It was {*status*}!

'));

$fullStories = array(

array('template_title'=>'{*actor*} just shared a {*nap-type*}

with {*target*}', 'template_body'=>'

"http://myserver.com/some_img.jpg" alt="Naps!"> It

was {*status*}!

'),

array('template_title'=>'{*actor*} just shared a nap with {*target*}

','template_body'=>'

Naps! It was {*status*}!

'),

array('template_title'=>'{*actor*} just napped.',

'template_body'=>'

alt="Naps!"> It was {*status*}!

'));

$bundleId = $facebook->api_client->feed_registerTemplateBundle

($oneLiners, $shortStories, $fullStories);

A few notes:

You have to include the one-line templates but can leave out either of the short or full templates by passing null into Feed.registerTemplateBundle().

The template_title fields have to start with the {*actor*} token, but you’re free to do whatever you’d like in the body fields.

The bundle ID returned in the code here can be used with the other Feed API calls for publishing stories and managing template bundles.

Discussion

Return Main Page Previous Page Next Page

®Online Book Reader