Contents
About
Help
Facebook Apps
Please do not save test edits. If you want to experiment, please use the
sandbox.
This section will show you how to create Facebook Apps that integrate with the The Facebook Platform. *Here's a basic hello-world program that displays inside a facebook "canvas".* import("facebook"); fb.init(); print("Hello Facebook World!"); ###Configuring for Facebook The first time you preview a Facebook app in the AppJet IDE, it will present a wizard for helping to configure your app integration with Facebook. ###Friends The facebook library creates the global object fb which contains some information about the current user of the Facebook app. Facebook users are identified by their "UID" (User ID), which is an integer. *The variable fb.friends contains an array of uids for the current user's friends.* import("facebook"); fb.init(); // require this app to be added, so we can access fb.friends fb.requireAdd(); printp("The Facebook User IDs of all your friends:"); print(fb.friends); ###API Calls The function fb.call lets you make calls to the Facebook API. Here is a list of all the API calls facebook supports. *Here is an example using fb.call to list the user's friends who have birthdays in the current month.* import("facebook"); fb.init(); fb.requireAdd(); var birthdays = fb.call("users.getInfo", { uids: fb.friends, fields: ["birthday"] }); var thisMonth = (new Date).toString().split(" ")[1]; print(H2("Here are all your friends who have birthdays in ", thisMonth)); birthdays.forEach(function(x) { if (x.birthday && x.birthday.indexOf(thisMonth) != -1) { printp(FB_PROFILE_PIC({uid: x.uid}), " ", x.birthday); } }); Note that we used the function FB_PROFILE_PIC to render a special kind of display. This is an example of what Facebook calls "FBML", the FaceBook Markup Language. FBML is like an extension of HTML, and you can use FBML tags in AppJet the same way you use HTML tags. ###Adding a Box on the Profile *Here is an example that allows a user to put some text in a box on their Facebook profile using fb.setProfileFBML().* import("facebook", "quickforms"); fb.init(); fb.requireAdd(); function post_callback_main() { var f = new QuickForm({action: "setprof"}); f.addInputTextArea("t", {label: "Put this on your profile:"}); f.addSubmit("s", "Make it so!"); print(f); } function post_callback_setprof() { fb.setProfileFBML(fb.uid, request.params.t); printp("It is done! ", link(fb.fullCanvasUrl, "go back")); } dispatch(); ###More Examples Here are some additional example facebook apps to help you get started. * fb-compliment-machine (advanced): A full-featured Facebook App that generates compliments with random sentence structure and vocabulary, and lets you send them to your friends.