Skip to main content

The new (as of March 2009 - who knows what next week holds) Facebook Pages have become more like regular Facebook profiles. The important thing to note for the purpose of this post is that they now have a Publisher that allows Page admins to set status messages for the page. And make no mistake - these are status updates just like you would set on your own personal profiles. Why is this important? First, it allows you to handle Pages as just another source for status messages, secondly, it integrates Pages more fully into the Facebook Feed model, and finally it's important to realize that it has created problems for some (see this for example.) Now that Pages are part of News Feed any status updates or posts made by a Page or will show up in your personal Feed. Obviously it makes sense to syndicate these status messages in as many ways as possible. But, the question is, how?

This post, first of a series on Facebook Pages, will begin the discussion by first talking about how you can get a Page's status from the API.

How do you get the status for a Page via the API?

You can get the Page's status by using one of the same API methods you do to get a normal user's status - you just use the PageID as the UserID parameter in the call. You will need a valid Facebook Session key to do this, however! I'll discuss what that means in my next post. Just remember that a Page cannot login to Facebook to get its own session key. To get that PageID you either snag it from Facebook's POST variables ('fb_sig_page_id') that are sent to a Page app's canvas page or copy it from the Page's URL (if you are going to be using it in places that may not have access to the POST variable or need to store it.)

Here's an overview of three ways of getting a Page's status:

Facebook Page Status: 3 Approaches
API (PHP) Notes Requires Session Key
users_getInfo returns text and time of last status message yes
status_get Not present in most Facebook PHP Client libraries, use raw API call instead. Allows you to return a number of statuses at once using limit parameter. yes
fql_query Excellent way to fetch only what parts of the status you need while making Facebook do the filtering on their end for you. Can minimize traffic to your servers; however, FQL can be slow. yes

So which way is 'best'?

It depends on what you need out of the status itself. For example, the first method above, using users_getInfo, only allows you to get the LAST status message for a given Page (or user.) For example it returns the following (PHP):

    [0] => Array
            [uid] => 714497440
            [status] => Array
                    [message] => is writing a blog post about Facebook Fan Pages
                    [time] => 1237687152
                    [status_id] => 7066343802

The second method, status_get, returns more information about each status message. Additionally, it lets you return more than one.
For example, either of these would return the last 2 status messages for user 714497440

                                                   array(  'uid'=>'714497440',

The results are shown below in JSON format since the PHP client return value does not offer associative names for the data:

      "message":"status message 0"

      "message":"status message 1"

Finally, using FQL allows you to filter down to only the relevant bit of information you need. For example, if you just want the ids of the last 5 statuses messages for a Page you can simply use this FQL query:

SELECT status_id FROM status WHERE uid = $pageID LIMIT 5

The beauty of the final approach is that it not only allows you to minimize the size of the return data from Facebook but it also can be used as part of the FQL preloading process that performs FQL queries before calling your canvas page. You still take the hit for the FQL call, but it save a round trip, and additionally removes the automatic sending of the currently-logged in user's entire friend list as part of the Facebook POST variables sent to your page! This can cut down on traffic if your app users have large numbers of friends. Since the average friend count on Facebook now stands at 120 this could be significant for long-term bandwidth costs. NOTE: the status_get API call basically returns the same result as this FQL query:

SELECT * FROM status where uid = $pageID ...

Hopefully this gives you some insight into the basic involved with getting a Facebook Page's status. In the next post I'll talk about how you handle this because Facebook requires a valid session key from a logged-in user to call any of these APIs. This can cause problems, for example, when you have code that runs without user interaction (via a cron job to update a Page profile tab for example.)

Stay tuned...


Post by Cappy Popp
Mar 28, 2009