Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [156]

By Root 756 0

$title .= 'Take a Nap!';

$title .= '';

$title .= '';

$wide = '';

$wide .= $title;

$wide .= 'This is the wide profile box for useyou="false" firstnameonly="true"/>!';

$wide .= '';

$narrow = '';

$narrow .= $title;

$narrow .= 'This is the narrow profile box useyou="false" firstnameonly="true"/>!';

$narrow .= '';

$narrowMain = '

This is the main narrow profile box !

';

// $markup, $uid, $profile, $profile_action, $mobile_profile, $profile_main

$result = $facebook->api_client->profile_setFBML(null, 12345, $wide . $narrow,

null, null, $narrowMain);

Retrieving FBML for a Profile Box is as simple as:

$boxFBML = $facebook->api_client->profile_getFBML(12345, 1);

$mainFBML = $facebook->api_client->profile_getFBML(12345, 2);

The first parameter is the uid of the user you want to retrieve for, and the second is either 1 for the wide and narrow Boxes or 2 for the main Profile’s narrow Box.

Don’t forget that you can preview your FBML using the FBML Test Console (http://developers.facebook.com/tools.php?fbml) before you post it, to make sure it renders correctly.

Get a User’s Info


Problem


I need to retrieve info about a specific user.

Solution


Use the Users.getInfo() method:

$uids = array('12345');

$fields = array('first_name','last_name');

$users = $facebook->api_client->users_getInfo($uids, $fields);

Discussion


You can query on any of the fields that make up the user table, which are documented in Figure 9-1. You might run into some of the privacy restrictions built-in to Platform, which limit the meeting_for, meeting_sex, religion, and significant_other_id fields to being visible to an app only when it has been added by a user. Users also have the option to limit the visibility of all fields except affiliations, first_name, last_name, name, and uid.

FQL equivalent


If you’d prefer to use FQL to access users, the equivalent query is:

SELECT uid, name, birthday FROM user WHERE uid IN ($uids)

See User Table for more information.

Get Logged-In User


Problem


I need to find the current loggedinuser’s uid.

Solution


Use the very simple Users.getLoggedInUser() method:

$currentUser = $facebook->api_client->users_getLoggedInUser();

Discussion


Users.getLoggedInUser() returns the uid of the current loggedinuser.

Has a User Added My App?


Problem


I need to check whether a user has added my app.

Solution


Use the Users.isAppAdded() method:

$hasAdded = $facebook->api_client->users_isAppAdded();

Discussion


Users.isAppAdded() returns a boolean indicating whether the specified user has installed your app. This will check for the current loggedinuser by default, but web-based Facebook apps can also pass in a different uid:

$hasAdded = $facebook->api_client->users_isAppAdded('12345');

Setting Status


Problem


I need to set the Facebook status of my users.

Solution


Use the Users.setStatus() method, which unfortunately isn’t supported in the PHP Client Library (see Adding Missing PHP Client Library Methods):

$result = $facebook->api_client->Users_setStatus('setting his status

using the API!',false);

The parameters, in order, are the status and whether or not to clear the status. Passing true for clear will ignore the status you pass in and leave it blank.

Discussion


You can set the status only for users who have given your application the status_update extended permission (see Extended Permissions for more information).

Users.setStatus() will also accept two additional parameters: a boolean called status_includes_verb, which will prepend “is” to the front of your status if you pass false, and a uid of the user for which you want to set the status (which is ignored for desktop apps and is required for web apps only if you don’t have a valid session).

Extended Permissions


Problem


I’ve planned out a great app,

Return Main Page Previous Page Next Page

®Online Book Reader