Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [149]

By Root 631 0

Get Friends Who Use My App


Problem


I need to retrieve all of the current loggedinuser’s friends who already have my app installed.

Solution


Use the Friends.getAppUsers() method:

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

This method has no parameters, and it can be called only for the combination of the current loggedinuser and your application.

Discussion


Friends.getAppUsers() returns an array of uids of the friends who have your app installed. 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 uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=$uid)

AND is_app_user

See App Friends for more information.

Get Friend Lists


Problem


I need to retrieve all of the friend lists for the current loggedinuser.

Solution


Use the Friends.getLists() method:

$friendLists = $facebook->api_client->friends_getLists();

This method has no parameters, and it can be called only for the current loggedinuser.

Discussion


Friends.getLists() returns an array of the flids (friend list IDs) for the current loggedinuser. You can retrieve the members of a friend list by calling Friends.get() and passing in the flid (see Get Friends).

You’re allowed to store the returned friend lists, but you should check them periodically because changes users make won’t be reported back to you. Friend lists are considered private, so you can’t share this information with anyone else.

FQL equivalent


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

SELECT flid, name FROM friendlist WHERE owner = $uid;

See Retrieving a User’s Friend Lists for more information.

Get Groups


Problem


I need to retrieve information about a set of groups, based on either a list of users or group IDs.

Solution


Use the Groups.get() method:

$groups = $facebook->api_client->groups_get();

If you specify no filters, you’ll get all the groups for the current loggedinuser. You can specify a different user’s uid to filter for them:

$groups = $facebook->api_client->groups_get(12345);

In that case, you’ll get something back only if the current loggedinuser is allowed to see the groups for the user you’ve specified. If you have one or more gids (group IDs) and just want to pull information on them, you can do that too:

$targetGroups = array('2248774311', '14740918186');

$groups = $facebook->api_client->groups_get(null, $targetGroups);

Discussion


Groups.get() returns a multidimensional array of group records, with each element containing the fields listed in Groups Table.

FQL equivalent


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

SELECT gid, name, description FROM group WHERE gid IN (SELECT gid FROM

group_member WHERE uid=$uid) AND gid IN ($gids)

See Groups Table for more information.

Get Group Members


Problem


I need to find all of the members of a group.

Solution


Use the Groups.getMembers() method:

$members = $facebook->api_client->groups_getMembers(12345);

where 12345 is the gid (group ID) of your target group.

Description


Groups.getMembers() returns a multidimensional array in which the first level of elements are the four membership types (members, admins, officers, not_replied), each containing the appropriate set of uids representing all of the members of that category whom the current loggedinuser is allowed to see. Note that the members array contains all of the admins and officers but does not overlap with the not_replied array. These lists are not filtered for users of your application, so note that they might contain users who don’t have it installed.

FQL equivalent


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

SELECT uid, gid, positions FROM group_member WHERE gid=$gid

See Listing Table for more information.

Creating/Modifying Marketplace Listings


Problem


I need to create or modify

Return Main Page Previous Page Next Page

®Online Book Reader