10 Things That Would Have Been Nice to Know When Starting My Facebook Application | padrenel's Blog
Alright, just finished my first Facebook app. Some pretty cool functionality they've built there, and it's mostly pretty straightforward to work with, but the documentation is lagging in some areas. Here's a few things I learned along the way, in no particular order - most may seem like no-brainers, but I know I lost some time to most of these!
1) They seem to be pushing php5, I needed to use php4. Cost me a day figuring out how to make this happen. They link to an unofficial php4 port off the developers page, but this isn't really functional as written. So, starting with this port, and using the official php5 api as a model, there are a few things to tweak. Get rid of the static methods, and the try/catch functionality. There are a a few places within the FacebookRestClient implementation that you need to prepend "$this->" to those previously static methods. For the constructor, it should be named after the class name, not "construct." Note that in facebook.php, the call to new FacebookRestClient has the wrong parameters.
This should help you get started if you need to use php4. Also note that if you download the php5, hidden in there is a folder with a php4 port - I haven't tried that one yet.
2) Session-keys - in putting together a simple app, I haven't found a need to store each user's session key. For cases where I need to push content to the profile, I just use my own (infinite) session-key, in a global sense. I can just do something like set_user($my_user_id, $my_session_key) - no need to call set_user for each installed user!
3) Updating profiles - there are a couple options here. In any case, first set the user's profile in the post-add script (profile_setFBML). Now, let's say you want to update a profile periodically, or on a certain action. From an action, it's easy - you already have the correct user (passed through fb_sig params), so just call profile_setFBML again.
To do a more periodic update, you can just iterate over all your users, get their uids, and call profile_setFBML() on each. Remember, from above, you don't need to call set_user for each, just use your own session_key.
Another option is to use fb:ref, as the documentation seems to recommend. For each profile, you initially set the original profile (using profile_setFBML) to something like "<fb:ref url="http://www.example.com/profile.fbml">". Then, when you want to update user's profiles, you can just update the fbml on your end (profile.fbml), and then call fbml_refreshRefUrl("http://www.example.com/profile.fbml") to push the update. Note, if your application displays the same fbml to each profile, you just need to call this refresh once. If you need to take the uid as a parameter, however, you still need to iterate over your users, calling refresh on each.
4) If you're developing multiple applications, make sure you check your api key and secret values. Sounds basic, but something I missed while cutting and pasting between apps, and the errors you see aren't quite obvious.
5) Speaking of errors, remember to use the few debugging tools they do give you. Use their test consoles to see what your query outputs will look like, and how your fbml will render. It's much easier to debug at this stage then in the running application. Once running, remember you can view source on any canvas page and see the original fbml, pre-rendered.
6) A lot of my errors stemmed from poorly-formed html / fbml - forgetting to close p tags, etc. Things that a normal browser wouldn't complain about will cause the Facebook parser to error out. Note, as the application developer, these errors will show up on your page. However, if you're working on a project with someone else, and you aren't the creator of the app, this output may not necessarily show.
7) Have some issues with how your fbml/html renders? Having problems laying something out just right? Use a tool like Firebug and/or Web Developer (both Firefox extensions) to help you examine the source. You can see how Facebook is styling your elements, what Facebook classes you can use in your own styling, etc. One example I ran into - trying to create a checkbox within an fb:editor form caused all sorts of sizing and layout issues. Looking at the css, Facebook had assigned a "width:100%" to the input tag. I overwrote this with a "style=width:auto;" and everything worked fine.
8) Get help if needed! Past their main documentation page, which can be a bit incomplete, check out the platform wiki. A ton of useful information here, including step-by-step tutorials and more detailed descriptions on the available fbml tags. I found it useful to monitor the developer group's discussion board - a lot of people going through similar issues and a wealth of tips and advice, both for people just starting out and for people looking for more advanced functionality. People are generally open and helpful - you might even make a new friend! Also check out the IRC channel - the conversation's a bit more disjointed, but Facebook employees are around to answer questions.
9) There's a major application directory backlog, so keep that time-line in mind while building an app. You can submit once done, but realize that you'll probably have a few days to deal with any final tweaks before it's actually reviewed.
10) Finally, have fun! There's a ton of possibility here, with Facebook opening up their network to the hordes of talented developers. Let's see some creative, novel, exciting apps out there!
If you appreciated this article, please consider adding our latest Facebook app, called, "My Moods"-- It lets you set custom moods, choosing from over 100 emotions and smileys. You can also mention your friends in your mood. We're pretty proud of it, and it exercises all of the lessons above. Thanks!
Also, check out our other application, My Goals. It allows creation of personal goals ("I will Climb Everest", "I will Pass Finals"), with optional deadlines, shared with your friends.
Previous Posts10 Things That Would Have Been Nice to Know When Starting My Facebook Application, posted June 6th, 2007, 7 comments
BlogrollHere are some friends' blogs...
HelpEmbed Photos Embed Videos
What's The Biggest Or Worst Impulse Purchase You've Made?
A fun new question each day. Winners get trophies and points.
Respond and Vote Now!