Post

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!

http://apps.facebook.com/mymoods/

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.




This Blog Entry's Comment Board (7 comments)
1-7 of 7 Comments   

jlipps
Posted on 03:39PM on Jun 7th, 2007
Great post! Wish it had been around when I started my app, too.

For the next step (releasing your app and helping its user base to grow), check out the tips sheet I put together here
jlipps
Posted on 03:40PM on Jun 7th, 2007
...That would be http://tinyurl.com/2akw2g (from http://www.insidefacebook.com/ - it was ******** from the previous comment)
Nabukaz
Posted on 07:17AM on Aug 14th, 2007
I knew in 5 secs I needed php5. It took me 3 days to set up the apache php 5 and mysql on my mac. It came with php 4.
sbgulfcoast
Posted on 08:46AM on Nov 6th, 2007
Hey I'd like to learn more about:
3) Updating profiles -
I just started playing around with facebook apps and I've gotten hung up on that issue. The info above is good but it's just not enough for a beginner like me to get that working. Any additional information would be great!
mkerr
Posted on 07:55PM on Jun 5th, 2008
If anybody wants a super fast (10 minute ) way to set up Apache, PHP5, and MYSQL as a windows development environment just give me a shout michaelckerr@gmail.com. I've been using this for a long time and have used it to set up on workstations in companies where I need to do something NOW. I't really saves days of brain bruising.
opensourcecoder
Posted on 03:54PM on Jan 25th, 2009
this is really a gr8 article and good help for new bees. Thanks buddy.

I hope you will enjoy my stay..
Don't miss my blog for good Face book update..

http://opensourcecoder.blogspot.com/

Thanks
Prashant Agarwal
abhinay009
Posted on 08:03AM on Aug 21st, 2013
if anybody want to run facebook app in localhost in php
mail me abhinay.bali@gmail.com
i will reply you....
Add Comment
1-7 of 7 Comments   
Your Comment:


Previous Posts
10 Things That Would Have Been Nice to Know When Starting My Facebook Application, posted June 6th, 2007, 7 comments

Blogroll
Here are some friends' blogs...

Help
How to Embed Photos in your Blog Embed Photos How to Embed Videos in your Blog Embed Videos
Caption of the Day

Today's Image:

A fun new caption image each day. Winners get trophies and points.
Play and Vote Now!