Facebook Cookbook - Jay Goldman [82]
Clicking the Add to Profile button will show a confirmation dialog like the one in Figure 6-41.
Figure 6-41. Add to Profile confirmation
Clicking on Add will take users to their Profile (on either the Wall or Boxes tab, depending on which tab they select in the subtitle of that dialog) and highlight the new box for them, as shown in Figure 6-42.
Figure 6-42. Keep Profile Box
Clicking on the Add to Info button will also show a confirmation (Figure 6-43).
Figure 6-43. Add Info section confirmation
Clicking Add takes them to the Info tab but doesn’t highlight the new section in the same way that the Profile button highlights the new box.
Prompting for Extended Permissions
Problem
I need to get permission from users to send them email, get an infinite session, update their status, upload and tag photos, and create or modify Marketplace listings. Is there an easy way to do that?
Solution
Sure is! Use the fb:prompt-permission button, which was added in the mid-2008 Profile redesign:
The tag will display the text (or any other FBML) you put into it as a link that opens a confirmation dialog like the one shown in Figure 6-44.
Figure 6-44. Prompt permissions confirmation dialog
Discussion
The following extended permission strings are available:
offline_access
status_update
photo_upload
create_listing
Facebook will show links (or other FBML) only for permissions the user hasn’t already granted you. You can optionally pass a next_fbjs parameter into the fb:prompt-permission tag to specify an FBJS function that you’d like called after permission has been granted, which gives you the option of hiding the link.
You Can Pick Your Friends
Problem
I need to give my users the ability to pick one of their friends. How can I give them a text field that will filter their friend list as they type?
Solution
Use the fb:friend-selector tag to render a predictive text field into your forms. The simplest form is:
which will give you a form field like the one in Figure 6-45.
Figure 6-45. The fb:friend-selector field before typing any text
When users start typing in the field, it will immediately show them potential matches, as in Figure 6-46, which can then be selected using the up/down arrow keys.
Figure 6-46. The fb:friend-selector field after text has been entered
Discussion
You can specify a uid for the selector if you’d like to give people the option of selecting from someone else’s friends. Facebook will take care of the potential privacy violation by not listing any friends if the loggedinuser shouldn’t see them (by default, the selector uses loggedinuser as the uid so that they’re picking from their own friends).
The control works by using JavaScript to set the value of a hidden field when your user makes a selection in the predictive list. Pass in name and/or idname parameters to set the names of the actual selector field and the hidden field, respectively:
Your handle.php file will receive the current contents of the name field and the last user selected in the idname field (using, in this case, marks_friends and selected_friend as keys in $_POST).
NOTE
Facebook CEO Mark Zuckerberg has the lowest Facebook uid: 4. The numbers stopped being consecutive at some point, so although my uid is 561415460, I obviously wasn’t the 561,415,460th user.
There are three parameters that give you control over the contents of the list: include_me, which takes a boolean value that defaults to false