Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [86]

By Root 719 0
app already and are

// friends with this user

$friends = $facebook->api_client->fql_query("SELECT uid FROM user

WHERE has_added_app=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = $user)");

// Parse into a comma-separated list

$excludeList = '';

if($friends){

$excludeList .= $friends[0]['uid'];

for( $counter = 1; $counter < count($friends); $counter++ ){

if($excludeList != ''){

$excludeList .= ',';

}

$excludeList .= $friends[$counter]['uid'];

}

}

// Build your invite text

$inviteContent = htmlentities('="true" shownetwork="false"/> says this is the most awesomest Super Disco

Napping application ever made. Come take naps with objective="true" uid=" ' . $user . '"/>!');

$inviteContent .= htmlentities('label="Take Naps with Me!" />');

?>

Now you’re ready to output the FBML for your selector:

action="http://www.someserver.com/post_invite.php"

invite="false"

type="Disco Nap"

content="">

actiontext="Here's a list of friends who don't take Super Disco Naps:"

exclude_ids="echo $excludeList?>"/>

Inviting/requesting a small number of specific friends


Use fb:multi-friend-input when your users will have very specific friends in mind (rather than when they want to browse through all of their friends). This is particularly true when your layout doesn’t have space for an entire fb:mutli-friend-selector, even in condensed mode. See You Can Pick Your Friends (in Batches) for details. Note that you’ll need to include an fb:request-form-submit tag if you use fb:multi-friend-input, since it won’t render its own submit button.

Inviting/requesting a single user


Use fb:friend-selector when you need to prompt your users for one friend. This is particularly useful when they’re doing something like challenging a friend to a game or sending someone a gift and you only support one-to-one interactions. See You Can Pick Your Friends for details. Note that you’ll need to include an fb:request-form-submit tag if you use fb:friend-selector, since it won’t render its own submit button.

NOTE

For information on actually sending Notifications and the like, see Chapter 9.

Predicting the Future with Type-Ahead Controls


Problem


I love the type-ahead control that Facebook provides in the fb:friend-selector (see You Can Pick Your Friends), but I want to use it for things other than friends.

Solution


Use the fb:typeahead-input tag, which is currently in beta. The simplest form is:

method="post">

Red

Yellow

Green

This tag is supported only in FBML v1.1, so you’ll need to make sure to wrap it in the fb:fbml tags or you’ll get an error about it not being supported in this version.

Discussion


In the example just shown, the handle.php page will receive the value of the form as the color parameter. If you don’t provide a name for your field, you won’t be able to access the value later, so it’s probably a good idea.

You can use FBML inside of the fb:typeahead-options tag if you’d like to include dynamic information, including names of users:

uid="12345" linked="false" useyou="false" />

The type-ahead field is particularly useful when combined with an API call to provide users a choice from a long list of Facebook-related content. You could, for example, use the API to pull in a list of all of the groups this user is a member of:

method="post">

®Online Book Reader