Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [155]

By Root 670 0

'12345',null,50,50,null,null);

The parameters, in order, are the pid (photo ID) of the target photo; the uid (user ID) of the user you’re tagging (set to null if this is a text tag); the text to tag (set to null if this is a user tag); the x coordinate of the tag; the y coordinate of the tag; a JSON-formatted array of tag information; and the uid of the owner of the photo (if it isn’t the current loggedinuser).

Discussion


Tags can only be added to pending photos owned by either the current loggedinuser or the user specified in the last argument, unless your app has been granted the photo_upload extended permission (see Extended Permissions for more information).

The parameters for Photos.addTag() are pretty self-explanatory, except for the optional tags JSON-formatted array. If you pass a tags array, the tag_id, tag_text, x, and y parameters are ignored. The tags string should be constructed of x and y values accompanied by either a tag_uid or tag_text:

[{"x":"30.0","y":"30.0","tag_uid":12345}, {"x":"70.0","y":"70.0","tag_text":"

Joe's skateboard"}]

If you’re building your app in PHP 5.2 or higher, you can create a regular PHP array and then use the built-in JSON encoder (other languages may have equivalent functions; check your documentation):

$tags = array(array('x'=>50,'y'=>50,'tag_uid'=>'12345'),

array('x'=>25,'y'=>40,'tag_text'=>'Pizza!'));

$result = $facebook->api_client->photos_addTag('1234567890123456789'

,null,null,null,null,json_encode($tags),null);

Getting and Setting Profile FBML


Problem


I want to get and set the contents of my users’ Profile Boxes and Profile Action links.

Solution


Use the Profle.getFBML() and Profile.setFBML() methods to manipulate the contents of your app’s Profile Box.

Discussion


The process of setting FBML is similar to the process that takes place behind the scenes when a user requests a page from your app (see Under the Hood: How Facebook Apps Work). In this case, the process is less symmetrical, since you initiate an update to Facebook’s cache that they’ll later display. The FBML update flow is illustrated in Figure 9-17.

Figure 9-17. FBML update flow

The FBML you set is cached on Facebook’s servers to make displaying Profiles as quick as possible, so you’ll need to use Profile.setFBML() again if you want to update the cache:

Whenever your app feels the need to update Profile FBML, you call Profile.setFBML() from your app server and send your new content to Facebook’s servers, where it gets cached. This generally happens either because you have a user currently logged in who has done something Profile-worthy, or because you have a scheduled job (possibly using cron) that has resulted in a calculation.

A visitor to one of your users’ Profiles requests the page from Facebook.

Facebook renders your cached FBML into HTML (along with all of the other cached Profile Boxes and Action links for this user) and serves it back to the visitor’s browser.

There are four parts to setting the FBML: the wide Profile Box, the narrow Profile Box, the main Profile Box, and the mobile Profile Box. The main Profile Box was added in the mid-2008 Profile redesign and gives apps the opportunity to have a version of their Profile Box added to the Wall page, limited to a height of 250 pixels.

We’re going to leave the mobile Box out for now and just focus on the other three. Here are three important things to note in the code shown next:

The wide and narrow Boxes are passed together as the Profile argument.

The first argument used to be markup, but it’s been deprecated. It’s still in the method call in the PHP Client Library, so you have to pass a null for it.

The fourth argument used to be profile_action, but it’s also been deprecated with the mid-2008 Profile redesign, so pass a null there, too:

$title = 'Super Disco Naps';

$title .= '';

$title .= 'Displaying 10 of 3200 naps ';

$title .= '';

Return Main Page Previous Page Next Page

®Online Book Reader