Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [148]

By Root 654 0
that didn’t require a login to access (both for attracting users and to open them up for indexing by search engines). Note that you can add only one Info box per application, so subsequent calls to Profile.setInfo() will simply overwrite earlier calls.

The other three tags are outlined next.

Getting Info sections


You can retrieve content you’ve set in an Info section by calling Profile.getInfo():

$infoSection = $facebook->api_client->profile_getInfo(561415460);

where 12345 is the uid for which you want to retrieve your section. This will return an array containing the same nested array structure you used to create the section (see the earlier example).

Adding options


Users can edit their Info section right on the Info tab, so it’s a really good idea to pre-populate the options they can add (especially if you’re using an object-based section). Call the Profile.setInfoOptions() method to add some options for the type-ahead control:

$options = array(

array(

'label'=>'Siesta',

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

array(

'label'=>'Cat Nap',

'link'=>'http://apps.facebook.com/superdisconapping/define/catnap'));

$infoOptionsResult = $facebook->api_client->profile_setInfoOptions

($options,'Favorite Naps');

The second parameter is the name of the field set when you called Profile.setInfo().

Getting Options


You can retrieve the options defined for a field by calling the method Profile.getInfoOptions():

$infoOptions = $facebook->api_client->profile_getInfoOptions('Favorite Naps');

FQL Queries


Problem


I need to run an FQL query.

Solution and Discussion


See Chapter 8, which covers FQL in great detail.

Friends?


Problem


I need to determine whether two (or more) users are friends.

Solution


Use the Friends.areFriends() method:

$areFriends = $facebook->api_client->friends_areFriends('12345', '67890');

The method also accepts two arrays and will let you know whether each pair (pulling the member at the same position in each array) is a friend:

$aUsers = array('12345', '67890', '11223');

$bUsers = array('33445', '66778', '99100');

$areFriends = $facebook->api_client->friends_areFriends($aUsers, $bUsers);

Discussion


Either way, the Friends.areFriends() returns a multidimensional array in which each element contains uid1, uid2, and are_friends elements (with the latter being true, false, or empty if the members aren’t visible due to privacy rules or don’t exist, which is the case with our fictional users here):

Array

(

[0] => Array

(

[uid1] => 12345

[uid2] => 33445

[are_friends] =>

)

[1] => Array

(

[uid1] => 67890

[uid2] => 66778

[are_friends] =>

)

[2] => Array

(

[uid1] => 11223

[uid2] => 99100

[are_friends] =>

)

)

Since the method is symmetric, both arrays need to have the same number of elements in them or you’ll get an invalid parameter error.

FQL equivalent


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

SELECT uid1, uid2 FROM friend WHERE uid1=uid1 AND uid2=uid2

See Checking Whether Two Users are Friends for more information.

Get Friends


Problem


I need to retrieve all of the current loggedinuser’s friends.

Solution


Use the Friends.get() method:

$friends = $facebook->api_client->friends_get();

You can optionally specify a flid (friend list ID) if you want to narrow the scope of the retrieval down to a single friend list:

$friends = $facebook->api_client->friends_get(12345);

You can find the flids for this user by calling Friends.getLists() (see Get Friend Lists).

Discussion


Friends.get() returns an array of uids for the matching friends.

This method will only return friends of the current loggedinuser. There is no way to call this for a different user. It is against the terms of use of Facebook Platform to store the returned values from this call.

FQL equivalent


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

SELECT uid2 FROM friend WHERE uid1=$uid

See Retrieving a User’s Friends for more information.

Return Main Page Previous Page Next Page

®Online Book Reader