I Can't Believe That Worked

Code and Ideas, minus the profanity (the one language all developers know)

Silverlight Facebook Client Side API v0.001

Hello All!

Lately, I have been spending some time working with Silverlight in the context of the Facebook api.  I've been amazed at the amount of data the api gives you access to.  With the incredible growth facebook is experiencing (check this out: http://www.insidefacebook.com/2008/07/29/tracking-facebooks-2008-international-growth-by-country/), there are many opportunities blooming for developers that can use the information to improve / innovate with their own products.  If you are a marketing / advertising business and you are not leveraging this information in one way or another, then I would say you are missing out!

In a past post (Facebook Connect Post) I showed everyone how to set up an application in Facebook and how to use Facebook Connect with Silverlight to create a simple login screen.  That was a trivial proof of concept to show how one might implement such things on their Silverlight App.  This post will build on the previous post, and introduce a very alpha version of a Silverlight client side api I have been working on for a little bit.  

There has been many articles written on how to hook up the a Silverlight app to Facebook, but it's always used the web server as a bridge to get the data back from the Facebook api.  Pete Brown did a wonderful job illustrating this in this blog post using the Facebook Developer Toolkit via Clarity Consulting.  I think using your web server as the bridge to the Facebook api is slightly wasteful.  As a result of that conclusion I decided to port the api to the client side.  I felt it would be nice to offload much of the weight of the web requests onto the Facebook servers rather than my poorly funded web servers :).  I also think this will allow for an architecture that will scale much better than the web server bridge.

<disclaimer>

If / When you look at the code, please understand this is just an api and a demo.  There is little or no abstraction.  There is no caching / real object model.  I built this as a proof of concept and will advance it in a bit.  Heck, I don't even know if this is going to garner any attention...

</disclaimer>

When I was building the api, I came to the conclusion, very early down the path, that web request completed event handlers and custom delegates are the devil, Bobby Boucher.  I always want to write the call to the method, then have to go back and wire up the delegate for the call back.  It bugs the hell out of me that I can't just pass an action into the method call.  With that thought in my head, I made the api use generic actions passed into the api requests rather than callbacks.  I'm not sure how this will go over, but I have found it a little easier to read.  I do love lambdas, so I might be a bit biased in that choice.

One important thing to note about the Facebook api:  It might not give you back what the xsd promises.  I think I have fixed all of the places where this issue cropped up.

After you download the code, there are few things you will need to do to run the demo app.  You will need to follow my original post to create an application in Facebook and get facebook connect set up for the demo.  Basically, after you get your application key and secret key, you just need to plug them into a couple spots (ApplicationContext.cs, Default.aspx, and your secret key in value for app setting "secret" in the web.config).  You may also need to update your service references to point to the fake host name you set up in your hosts file (from the previous post).  That should get you to the point where you have the demo running.

Comments are welcomed.  Bugs are welcomed.  Calling me a complete butthead is welcomed.  I will get back to you if you are kind enough to ask about something.

Finally, I have to give a couple shout outs.  Thank you very much to the Madison, WI .NET Users group for letting me use your members as a sounding board.  Lance Larsen and Travis Feirtag were kind enough to give me some time at the latest meeting.  Thank you very much guys.  Check them out at http://www.maddotnet.com/.  Last but not least, I want to give a big high five to the guys over at http://mightymeaty.members.winisp.net/blacklight.silverlight/.  They do some really cool stuff with Silverlight controls.  I'm continually impressed with the quality and UX this group creates.  If you look at the controls in the demo, you will notice i'm utilizing some of their controls and styles.  I would recommend testing out their stuff if you get a chance.

Twitter: David Justice

Code

kick it on DotNetKicks.com

Comments

Community Blogs said:

In this issue: Jonathan van de Veen, David Justice, Andrej Tozon, Patrick Keating, Timmy Kokke, Shawn

# January 24, 2009 1:07 PM

Silverlight Travel » Silverlight Facebook Client Side API said:

Pingback from  Silverlight Travel » Silverlight Facebook Client Side API

# January 25, 2009 3:15 AM

Silverlight Travel » Silverlight Facebook Client Side API said:

Pingback from  Silverlight Travel » Silverlight Facebook Client Side API

# January 30, 2009 1:40 AM

Josh said:

I would really like to get a demo of this up and running but i'm having trouble getting the spoofed domain to work. I've changed my hosts for 127.0.0.1 my.domain.com. I've setup my facebook application's return address: http://my.domain.com.

I can get the application to start at localhost:59101 no problem. But I get error from "connect.facebook.com/extern/login_status.php" because the domains don't match. So, I try http://my.domain.com I get another website, so I have to change my LAN Settings to use proxyserver my.domain.com port 80 (and tried 59101). When i refresh page, the page times out.

It seems port 59101 is hard-coded thru out the project. I tried every combination of: (hosts --> 127.0.0.1:59101) (facebook app settings --> my.domain.com:59101) (using my IIS with vir dir set to port 80 or 59101) (ie --> localhost:59101, localhost, my.domain.com, my.domain.com:59101) (Proxy Settings: my.domain.com:59101, my.domain.com, localhost, localhost:59101). It just doesn't work.

When i goto http://localhost:80 with IIS setup with vir dir to the application's web path I get the following error:

"HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid."

I've even tried replacing all references of localhost:59101 in the code to my.domain.com. No luck.

If you could be a little more descriptive about "update your service references to point to the fake host name", that would be spectacular. Is IIS needed, what proxy settings? I read your other post and it talks about a Web Cloud Service. I havn't tried that, but your description in this blog says I only need to change app id/secret and fake domain.

Please help.

Thanks!

# March 2, 2009 1:23 PM

Tim Anderson’s ITWriting - Tech writing blog » Flash library for Facebook, Silverlight library for MySpace said:

Pingback from  Tim Anderson’s ITWriting - Tech writing blog » Flash library for Facebook, Silverlight library for MySpace

# March 31, 2009 12:04 AM

Mike Brown said:

Kinda late to the party but I've found that using http://somesite.com redirects to localhost without any host hacking.

# May 15, 2009 10:50 AM

Microsoft Weblogs said:

Stories mentioned in this episode: Presidential Inauguration in Silverlight and Moonlight New Version

# August 27, 2009 3:08 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)