Professional Documents
Culture Documents
1. <?php
2. // Prepare the invitation text that all invited users will receive.
3. $content = <<<FBML
4. <fb:name uid="$user" firstnameonly="true" shownetwork="false"/> wants to know what your Favorite Games
are!
5. <fb:req-choice url="{$facebook->get_add_url()}" label="Add Favorite Games to your profile!"/>
6. FBML;
7. ?>
8. <fb:request-form action="http://apps.facebook.com/myapp/" method="POST" invite="true" type="Favorite
Games" content="<?php echo htmlentities($content);?>">
9. <fb:multi-friend-selector max="20" actiontext="Here are your friends who haven't added Favorite Games to
their profile. Invite them to share their Favorite Games today!" showborder="true" rows="5"></fb:request-form>
And, once your user clicks the “Send Invitation” button, they’ll be presented with a window
similar to the following, which demonstrates how the invite request will appear when their
friends receive it. Take note of the data (specifically the messages defined within the code)
being populated within the form and invitation itself.
1. <?php
2. // Retrieve array of friends who've already added the app.
3. $fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.
$user.') AND has_added_app=1';
4. $_friends = $facebook->api_client->fql_query($fql);
5.
6. // Extract the user ID's returned in the FQL request into a new array.
7. $friends = array();
8. if (is_array($_friends) && count($_friends)) {
http://facebook-friends.com/ Facebook Docs. All In One Place.
Once we combine this new code with the previous example, we’ll have a complete invite
form that allows users to invite their friends without having to worry if their inviting
current application users.
1. <?php
2. // Retrieve array of friends who've already added the app.
3. $fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.
$user.') AND has_added_app = 1';
4. $_friends = $facebook->api_client->fql_query($fql);
5.
6. // Extract the user ID's returned in the FQL request into a new array.
7. $friends = array();
8. if (is_array($_friends) && count($_friends)) {
9. foreach ($_friends as $friend) {
10. $friends[] = $friend['uid'];
11. }
12. }
13.
14. // Convert the array of friends into a comma-delimeted string.
15. $friends = implode(',', $friends);
16.
17. // Prepare the invitation text that all invited users will receive.
18. $content = <<<FBML
19. <fb:name uid="{$user}" firstnameonly="true" shownetwork="false"/> wants to know
what your Favorite Games are!
20. <fb:req-choice url="{$facebook->get_add_url()}" label="Add Favorite Games to your
profile!"/>
21. FBML;
22. ?>
23. <fb:request-form action="http://apps.facebook.com/myapp/" method="POST"
invite="true" type="Favorite Games" content="<?php echo htmlentities($content);?>">
http://facebook-friends.com/ Facebook Docs. All In One Place.
Voila! Your users can now invite their friends to try out your application!
Cheers!