Feeds

Surviving the Facebook app 'swamp' with Azure

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

Protecting against web application threats using SSL

“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. ®

Choosing a cloud hosting partner with confidence

More from The Register

next story
Wanna keep your data for 1,000 YEARS? No? Hard luck, HDS wants you to anyway
Combine Blu-ray and M-DISC and you get this monster
US boffins demo 'twisted radio' mux
OAM takes wireless signals to 32 Gbps
'Kim Kardashian snaps naked selfies with a BLACKBERRY'. *Twitterati gasps*
More alleged private, nude celeb pics appear online
Google+ GOING, GOING ... ? Newbie Gmailers no longer forced into mandatory ID slurp
Mountain View distances itself from lame 'network thingy'
Apple flops out 2FA for iCloud in bid to stop future nude selfie leaks
Millions of 4chan users howl with laughter as Cupertino slams stable door
Students playing with impressive racks? Yes, it's cluster comp time
The most comprehensive coverage the world has ever seen. Ever
Run little spreadsheet, run! IBM's Watson is coming to gobble you up
Big Blue's big super's big appetite for big data in big clouds for big analytics
Seagate's triple-headed Cerberus could SAVE the DISK WORLD
... and possibly bring us even more HAMR time. Yay!
prev story

Whitepapers

Secure remote control for conventional and virtual desktops
Balancing user privacy and privileged access, in accordance with compliance frameworks and legislation. Evaluating any potential remote control choice.
WIN a very cool portable ZX Spectrum
Win a one-off portable Spectrum built by legendary hardware hacker Ben Heck
Storage capacity and performance optimization at Mizuno USA
Mizuno USA turn to Tegile storage technology to solve both their SAN and backup issues.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?
The next step in data security
With recent increased privacy concerns and computers becoming more powerful, the chance of hackers being able to crack smaller-sized RSA keys increases.