Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [147]

By Root 717 0

NOTE

The delicious photo of a delicious-looking plate of French toast is courtesy of urbanshoregirl, who published it on Flickr under a Creative Commons license. You can find the original photo at http://flickr.com/photos/urbanshoregirl/101749649/.

That’s pretty interesting and might attract my friends’ attention if it made it into their News Feeds, but it has to compete against all the other stories out there, so the odds are pretty slim (which I won’t be after eating that plate of food). If we take advantage of aggregation, Facebook can pick out that my brunch story is the same as the ones published by my wife and our friend Jason, and it can aggregate them together into one story, as in Figure 9-12.

Figure 9-12. News story, aggregated

This News story is quite likely to be true, since we all have brunch together a lot. Unfortunately, it’s only part of the story, since Jason’s wife Athena isn’t on Facebook. A more accurate aggregated story might be the one in Figure 9-13.

Figure 9-13. Factually accurate News story, aggregated

Aggregation used to be much more complicated before Feed.publishUserAction() came along, requiring you to make sure that the content in the title and body of your stories was identical. Now that we have the joy of registered template bundles, Facebook will try to aggregate any stories that use the same templates, falling back to the simplest (i.e., the last) template in the one-line, short, or full story formats. For more information, see Three Story Sizes: Working with Template Bundles.

Setting Info Sections


Problem


My app has collected some fantastic info about my users, and I’d like to add it to their Info tabs as structured data.

Solution


The mid-2008 Profile redesign introduced the ability for applications to add sections to the new Info tab, accomplished through a new family of four API calls and a new FBML tag.

Setting an Info section is fairly simple, though the nested arrays can be a little confusing:

$info_fields = array(

array(

'field'=>'Favorite Naps',

'items'=>array(

array(

'label'=>'Disco Nap',

'link'=>'http://apps.facebook.com/superdisconapping/define/disconap'),

array(

'label'=>'Super Disco Nap',

'link'=>'http://apps.facebook.com/superdisconapping/

define/superdisconap'),

array(

'label'=>'Power Nap',

'link'=>'http://apps.facebook.com/superdisconapping/

define/powernap'))),

array(

'field'=>'Favorite Napping Locales',

'items'=>array(

array(

'label'=>'Car',

'link'=>'http://apps.facebook.com/superdisconapping/locale/car'),

array(

'label'=>'Office',

'link'=>'http://apps.facebook.com/superdisconapping/

locale/office'))));

$infoResult = $facebook->api_client->profile_setInfo('Super Disco

Napping', 1, $info_fields, 12345);

If you read down from the top, info_fields is an array that contains a field name and an array of items. Each item contains, at a minimum, a label and a link, but can also contain image, description, and sublabel fields (the example here keeps it simple and uses only label and link). The actual call to Profile.setInfo() accepts a name for the Info section, either 1 for a text-based section or 5 for an object-based one (see the Discussion for more details), your array of data, and the uid of the user you’re setting the section for.

Discussion


As outlined in Info Sections, you can include either text-based or object-based sections. You can fit a lot more information into a much smaller area if you use the text-based option, but people are like magpies and are attracted to bright, shiny images, so you’ll probably get more clicks if you go the object route.

Since the links on items can go anywhere, add as many links into your application as you can. Users surfing their friends’ Info tabs will see your tantalizing links and follow them right into your app, where they will hopefully grant you access and install it themselves. In the example here, the Super Disco Napping app now includes a section that defines different types of naps and locations for taking them in, which would ideally be unprotected content

Return Main Page Previous Page Next Page

®Online Book Reader