Powered by discountASP.NET
referal ID: sdtref
Why recommend discountASP.NET?
$720 in referrals so far!

About/Contact

Steve Trefethen

Steve Trefethen is a Software Architect and Director of Software Training at Falafel Software in Capitola, CA. You can reach Steve here.

All opinions you read here are Steve's own and are not necessarily those of Falafel Software.

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Disclaimer

The posts on this weblog are provided AS IS with no warranties, and confer no rights. The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
If you're new here, you may want to subscribe to my RSS feed, follow me on Twitter, or subscribe via email. Thanks for visiting!

An HttpHandler for use with Facebook

June 18 2009 5:40AM

imageIn my SocialMine Facebook application, which uses MIT’s Simile Exhibit, I needed to fetch Facebook FQL query results from the Exhibit client-side JavaScript. While it may not sound that complicated it’s not something directly supported by the Facebook Developer Toolkit (FDT). I created an HttpHandler to respond to the Exhibit requests for the JSON data which populates the Exhibit. The HTTP request includes a Referrer header that contains the necessary data, fb_sig_user and fb_sig_session_key to construct an instance of facebook.Components.FacebookService. For completeness here is a list of the queryparams contained in the Referrer URL with the important lines highlighted:

auth_token=1379094a2a42e1c0037a33048912a875
fb_sig_in_iframe=1
fb_sig_locale=en_US
fb_sig_in_new_facebook=1
fb_sig_time=1245301045.1412
fb_sig_added=1
fb_sig_profile_update_time=1241328269
fb_sig_expires=0
fb_sig_user=719571200
fb_sig_session_key=c93185e145713ce98d72dfc2-719571700
fb_sig_ss=57abbef0284354d029fe8a19fa00dfce
fb_sig_ext_perms=offline_access,email,auto_publish_recent_activity
fb_sig_api_key=33c52d0a0c9867f677a1f05154c28478
fb_sig_app_id=5012360767
fb_sig=9ad664af23910ca18aeb203203c366cd

My HttpHandler is an abstract class with a single abstract method called FacebookRequest that descendents override to handle the request. As you can see below the handler itself is quite simple, parsing the queryparams into a Dictionary, creating an instance of the FacebookService and calling FacebookRequest passing the service instance and the HttpContext passed to the handler.

public abstract class FacebookHandler : IHttpHandler
{
    private const string REQUEST_SESSION_KEY = "fb_sig_session_key";
    private const string REQUEST_USER_ID = "fb_sig_user";

    #region IHttpHandler Members

    public bool IsReusable
    {
        get { return false; }
    }

    void IHttpHandler.ProcessRequest(HttpContext ctxt)
    {
        facebook.Components.FacebookService f = new facebook.Components.FacebookService();
        f.ApplicationKey = WebConfigurationManager.AppSettings["APIKey"];
        f.Secret = WebConfigurationManager.AppSettings["Secret"];

        Dictionary<string, string> dic = new Dictionary<string, string>();

        string[] split = ctxt.Request.UrlReferrer.Query.Split(new char[] { '?', '&', '=' });
        // Skip the first item since it’s the "?"
        for (int i = 1; i < split.Length - 1; i += 2)
        {
            if(i < split.Length)
                dic.Add(split[i], split[i + 1]);
        }

        f.SessionKey = dic[REQUEST_SESSION_KEY];
        f.uid = Convert.ToInt64(dic[REQUEST_USER_ID]);
        FacebookRequest(f, ctxt);
    }
    #endregion

    protected abstract void FacebookRequest(facebook.Components.FacebookService fbservice, HttpContext ctxt);
}

The JavaScript of Simile Exhibit requests the JSON data using the following LINK tag:

<link href="friendsjson.aspx" type="application/json" rel="exhibit/data" />    

The reference to friendsjson.aspx isn’t actually an ASPX as it’s handled by a descendent of this HttpHandler which is registered in the httpHandlers section of the web.config as follows:

<add verb="*" path="friendsjson.aspx" type="FBFQL.JSONHandler" />
In my application the FacebookRequest method queries using FQL for profile data and returns a JSON result that populates the Exhibit.

Btw, if you're looking for help on Facebook development be sure to read my wiki article.
FacebookDel.icio.usDigg It!

Tags: , ,

Mining your Facebook social network

April 28 2009 7:33AM

imageMany months ago, well before the latest Facebook redesign, I wrote an application to explore my Facebook social network in what I think is a fun and interesting way. Leveraging MIT’s Simile Exhibit project I developed SocialMine, an application that surfaces many attributes of your network’s profile information allowing you to filter and otherwise “mine” the data. As this is the hallmark of any Exhibit application, within the genre, I’d consider it to be quite plain were it not for the personal relevance of the data. Still, you can extensively filter the information in a live view including a Google Map.

Since the application relies on user provided profile data there may be cases where it simply doesn’t/won’t “work”. For example, I discovered a little over half of my friends haven’t specified a current location so they don’t appear on the map. On the other hand, I now know who those people are and can bug them to update their profile. :-) At any rate, I’ve had fun “mining” my network and thought you might too.

Lastly, having been developed for fun in my extremely limited free time largely after 12AM, SocialMine is by no means complete nor thoroughly tested. There I said it and should it fail utterly under load wouldn’t come as a huge surprise. FYI, if you have a lot of friends rendering the page could take significant time so consider yourself warned. For those interested, it’s written in C# using ASP.NET and based on my FDT Starter Kit. And now for those who find this a necessity a disclaimer…

Disclaimer: I make no warrantees expressed or implied, your mileage may vary, use at your own risk. For entertainment purposes only, accuracy of the rendered data is entirely control by your friends so consult them! Insert here any other relevant disclaimer related verbiage encompassing whatever problem(s) or situation(s) you may encounter while using SocialMine. Should you dislike SocialMine kindly remove it and simply move along. Consider yourself warned!

Now that that’s over, enjoy!

FacebookDel.icio.usDigg It!

Tags: ,

Facebook’s Disappearing Platform redux

April 13 2009 11:10PM

image About a month ago I wrote a post with some thoughts on what I felt the impact was on the platform as a result of the UI redesign. Today, I ran across this post on AllFacebook.com titled Top Facebook Applications See 25 Percent Drop In Traffic Since Redesign. Where Nick O’Neil states:

If you thought the last redesign spelled the death of the Facebook platform, you ain’t seen nothing yet! Last July Facebook released their new design and within a matter of months, widget applications had become a thing of the past. A few of those applications were able to withstand the changes but there’s a grim picture being painted weeks after Facebook’s latest redesign.

He goes on to provide some additional statistics and spells out the fact that it’s not all “gloom and doom”. At present, I’m quite skeptical about the Facebook Platform being worthy of the development time and effort in light of the near constantly shifting playing field.

The graphic I included displays the stats for my Facebook Starter Kit application with March 20th (mentioned in the article) highlighted, where it’s clearly visible even this simple application exhibits a similar drop off though I can’t say for sure this wouldn’t have happened naturally as it is a “Seinfeld” of applications.

FacebookDel.icio.usDigg It!

Tags:

Facebook’s Disappearing Application Platform

March 16 2009 8:21AM

W
ith each refinement to the Facebook UI it seems their application platform is taking a back seat to the desire of chasing after millisecond status updates a la Twitter and with this latest round applications seem to have all but disappeared. When the platform first rolled out there was a period of rapid developer adoption largely due to the potential audience size an application could field in a short period of time, that viral affect that was so popularized. The excitement continued for quite some time though I think in some cases Facebook must have become envious as it seems others were perhaps having more commercial success on their platform than Facebook itself if not in real terms perhaps in relative terms.

In the beginning, applications played a prominent roll and “installing” new applications was perhaps all too easy. I’d refer to those as the “wild west” days with the ensuing gold rush period that was eventually killed off. Ever since then it seems Facebook as increasing clamped down user’s exposure to third party applications and in many cases made it difficult and costly to keep an FB application up and running successfully over time as the API continues to be a moving target.

With the latest round of UI changes I couldn’t find a link to Facebook’s own Developer’s application, which I have “installed” on my account allowing me to review the FB applications I’ve created. Eventually, I found a round-about path through the Settings|Application Settings menu though that seems quite counter intuitive. Clearly, the rules of engagement for applications have changed dramatically over the platform’s brief lifetime so much so I’d be interested in statistics regarding how the viral nature of Facebook applications has been altered since the early days though I suspect we’ll never know. I think if you were fortunate enough to get in early and earn a respectable size audience you’re probably doing just though I’d suspect that’s not nearly as repeatable as one might hope given the current situation.

Facebook has something unique with their platform and garnered a developer audience quickly though it seems bent on following in Apple’s footsteps by locking it down so tightly they’ll end up thwarting the majority of developer’s who’d write applications they wouldn’t have the time nor wherewithal to write. These days it’s almost looking like Facebook would have preferred Facebook Connect rather than their platform route as that’s certainly the direction their pushing. At this point, let’s just say I’m glad I’m not working for a company in the midst of developing a Facebook application hoping to reach my target audience.

FacebookDel.icio.usDigg It!

Tags:

Growth of a Facebook Application

February 12 2009 7:34AM

image I’ve written what I consider to be sort of a Seinfeld of Facebook applications, an app about “nothing”. I’m talking about my Facebook Starter Kit application which you can add to your Facebook account here. The application, pictured to the right, has a total of three pages:

  1. Main page (pictured) which lists all your friends with their photo and a link to their profile page
  2. An XFBML page that illustrates usage of XFBML via JavaScript on an IFrame canvas page
  3. An FQL query page that allows you to test FQL queries with a list of your friends Facebook ID’s as well as your ID for convenience

And that’s it.

By the Numbers

What I’ve found fairly interesting is watching the apps statistics, provided by Facebook, which are quite extensive. Here are some basic stats from from January 28th:

Facebook app usage Jan 28th, 2009

And two weeks later:

Meaning my “app about nothing” attracted roughly 10 new users a day over the past two weeks. Here is a chart of active users over the past few months:

image

The inflection point is Dec 24th 2009 which is interesting because I’ve read Facebook had a very big Christmas with regard to traffic. I’ve done little to actually “market” this application other than blog about the Starter Kit and post a link to my wiki article.

Anyway, I thought this mildly interesting and it will be fun to watch where the stats go from here. I noticed today that the FDT now has +17K downloads and I know that no where near that number of people are using my Starter Kit so there is “room for growth”. :-)

Anyone else have interesting FB app stats to share?

FacebookDel.icio.usDigg It!

Tags: ,

ASP.NET Facebook Starter Kit for VS.NET 2008 updated to v0.8

December 29 2008 4:33PM

I’ve updated my ASP.NET Facebook Starter Kit with the following improvements/changes:

  • Added support for dynamically resizable iframe which avoids a scrollbar though may have some side effects/caveats. Code is based on JavaScript sample from Facebook.
  • Added an example of XFBML which requires xd_receiver.htm (included) allowing for a Cross Domain Communication Channel
  • Added example of using FQL, refer to FQL.aspx
  • Updated Facebook Dev Toolkit assemblies
  • Added Facebook stylesheet from Bill Konrad

The download is here and full directions for installation and use are here. To see this application running on Facebook click here. As always, please direct questions on the Facebook API to the Developer’s Forum, or on the Facebook Developer’s Toolkit to the discussion list.

[Updated: Jan 15, 2010] This post is now outdated so please look for my updated versions. The latest is always available on my wiki.
FacebookDel.icio.usDigg It!

Tags: , .NET | Facebook | Programming

Facebook Developer Toolkit now supports JSON results on FQL queries

December 03 2008 5:49PM
Facebook’s query language (FQL) allows fetching results as JSON by supplying an additional "format=json" parameter as part of the request. I submitted a patch a few days ago that adds a UseJson property to the FQL object which was recently added to the Toolkit.

So, to fetch JSON results for FQL queries you can use the following:

facebook.fql q = new facebook.fql(Master.API);
q.UseJson = true;
string result = q.query("SELECT ...");
Be sure to grab the latest sources of the toolkit. Btw, the main reason for even mentioning it is that unless you’re reviewing the toolkit source code it’s unlikely you’d even know it’s there so this post will hopefully help people searching Google for the answer.

Take a look at this post to see how the JSON format can be useful for using Facebook data using an HttpHandler.

FacebookDel.icio.usDigg It!

Tags: ,