Feeds

Surviving the Facebook app 'swamp' with Azure

Cloud platform, cloud client. Is Facebook and Microsoft Azure the perfect fit?

Build a business case: developing custom apps

“Developing with Facebook is like building a house on a swamp,” says Microsoft’s Nathan Totten. He should know. He used to work at social media company Thuzi, and when the company needed to write a C# Facebook application, he and his colleague Jim Zimmerman were so disappointed by the existing C# SDKs that they built their own.

Nathan Totten, technical evangelist at Microsoft. Totten is now a technical evangelist at Microsoft, and his project has become the open source Facebook C# SDK with a measure of approval from Microsoft as the suggested way to build C# applications for Facebook.

So why is Facebook development swamp-like? The first problem is that the Facebook API changes over time, and any wrapper you build on top can soon get out of date. The second problem is that Facebook does not officially support C#. It has SDKs for JavaScript, Apple iOS, Android and PHP.

In mitigation, the dynamic features of C# 4.0 are actually well-suited to APIs that are in flux, as Totten explains in his post mentioned above. Some API changes and additions can be accommodated without changing the SDK at all. This has also made it possible to make the C# SDK somewhat similar to the PHP SDK, which is an advantage when you are consulting the Facebook documentation.

Nevertheless, there are challenges. I tried the SDK with a simple Facebook canvas application, hosted of course on Azure. A canvas application is one that is embedded into a Facebook page. I started with an ASP.NET MVC 2.0 application, then added a reference to the Facebook C# SDK using NuGet, Microsoft’s package manager.

Facebook and Azure screenshot

Up and running: a Facebook Canvas app written with C# and hosted on Azure

To develop the app, I configured the application on Facebook to link to the web page running on localhost. Facebook apps generally request permission from their users to access personal information. In principle, the Facebook C# SDK makes this easy by using attributes. My app queries user status, so I annotated a method with:

[CanvasAuthorize(Permissions = "user_status")]

At runtime, Facebook popped up a dialog requesting permission. Easy. Unfortunately I soon ran into problems. After the user grants permission, you have to include an access token in calls to the Facebook API. There are several kinds of access token, and getting this right can be tricky.

Simple attributes in the code prompt the correct Facebook permission prompts.

I also discovered that the Facebook C# SDK is barely documented. A documentation link on the open-source site has no reference material, just a few examples and links, some of them out of date. Another problem cropped up.

I deployed my working app to Azure and it no longer worked. The reason, I discovered, is that some browsers block cookies from sites running in iFrames. If you ever have to debug a problem like this, which works locally but not on Azure, you will be grateful for an Azure feature called Web Deploy.

Normally, whenever an application is published to Azure, the cloud platform creates a new virtual machine, copies it, and then spins up the copy. This is why publishing to Azure takes a long time. Web Deploy, by contrast, updates the application on an existing VM, which takes only a moment.

Once you have debugged successfully, you still need to publish properly as otherwise the VM may revert to the original upload. There are hassles then, and it is curious that Microsoft and Facebook have not done more to make it easy to build C# Facebook applications. Having an open-source library is all very well, but it needs proper documentation, as does the companion Windows Azure Toolkit.

Once you have the plumbing right though, there is some sense in it.

Nothing insurmountable

Enteraction, a UK games company, uses Azure and the C# for its social media gaming framework, called GameShaper. According to operations director Arthur Barker, Azure provides scalability while being compatible with familiar Microsoft-platform technologies.

Developing with Facebook is like building a house on a swamp

Enteraction uses the Facebook C# SDK to get round Facebook’s lack of support for C# and .NET. “We have experienced a few teething issues, but nothing insurmountable nor unexpected for an SDK of limited maturity,” Barker told me. “Overall we are very happy with Azure.”

It is not essential to use the Facebook C# SDK, and another developer told me that he prefers to roll his own; it may take longer, but at least you know how it works.

Nevertheless, from the point of view of Facebook integration, using C# instead of PHP does feel like rolling a ball uphill. Then again, the integration points are likely to be only a small part of the whole, and if Visual Studio and Microsoft SQL Server are familiar, the benefits of using them can outweigh a little pain at the Facebook end. ®

Boost IT visibility and business value

More from The Register

next story
Sysadmin Day 2014: Quick, there's still time to get the beers in
He walked over the broken glass, killed the thugs... and er... reconnected the cables*
Auntie remains MYSTIFIED by that weekend BBC iPlayer and website outage
Still doing 'forensics' on the caching layer – Beeb digi wonk
VVOL update: Are any vendors NOT leaping into bed with VMware?
It's not yet been released but everyone thinks it's the dog's danglies
BlackBerry: Toss the server, mate... BES is in the CLOUD now
BlackBerry Enterprise Services takes aim at SMEs - but there's a catch
SHOCK and AWS: The fall of Amazon's deflationary cloud
Just as Jeff Bezos did to books and CDs, Amazon's rivals are now doing to it
prev story

Whitepapers

Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
The Essential Guide to IT Transformation
ServiceNow discusses three IT transformations that can help CIO's automate IT services to transform IT and the enterprise.
Consolidation: The Foundation for IT Business Transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.
How modern custom applications can spur business growth
Learn how to create, deploy and manage custom applications without consuming or expanding the need for scarce, expensive IT resources.
Build a business case: developing custom apps
Learn how to maximize the value of custom applications by accelerating and simplifying their development.