Facebook Cookbook - Jay Goldman [86]
// 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(' Napping application ever made. Come take naps with $inviteContent .= htmlentities(' ?> Now you’re ready to output the FBML for your selector: invite="false" type="Disco Nap" content=""> exclude_ids="echo $excludeList?>"/> Inviting/requesting a small number of specific friends Inviting/requesting a single user NOTE For information on actually sending Notifications and the like, see Chapter 9. Predicting the Future with Type-Ahead Controls Solution 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 You can use FBML inside of the fb:typeahead-options tag if you’d like to include dynamic information, including names of users: 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:
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.
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.
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.
Use the fb:typeahead-input tag, which is currently in beta. The simplest form is:
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.