BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News C# and VB .NET Libraries to Google, YouTube, Facebook, and other Web 2.0 APIs

C# and VB .NET Libraries to Google, YouTube, Facebook, and other Web 2.0 APIs

This item in japanese

In a recent post on his blog, Scott Hanselman has compiled a list of .NET libraries useful to interface with some of the Web 2.0 APIs that have proliferated all over the web. He also provides examples on how to access those services. This is an excerpt of his list.

Digg

Digg's API is called REST and uses XML for communication. DiggApiNet is a .NET wrapper for the Digg API. Digg API.NET is another wrapper available on CodeProject. In the following example written by Hanselman, an XmlDocument is created and loaded from a specified URL, then the XML nodes are copied into Digg specific objects.

private const string get_popular = "http://services.digg.com/stories/popular/comments/{0}";

public DiggComments GetPopular()
{
return GetPopular(new Hashtable());
}
public DiggComments GetPopular(Hashtable args)
{
string uri = String.Format(get_popular, HttpBuildUrl(args));
return new DiggComments(Request(uri));
}
public DiggComments(XmlDocument xml_doc) : base(xml_doc, "events")
{
_comments = new List();
if (xml_doc.SelectSingleNode("events") == null
|| xml_doc.SelectSingleNode("events").SelectNodes("comment") == null) {
throw new DiggApiException("XML response appears to be malformed, or contains unexpected data.");
}
foreach (XmlNode node in xml_doc.SelectSingleNode("events").SelectNodes("comment")) {
_comments.Add(new DiggComment(node));
}
}

Facebook

Facebook has developed a complex API, and there is plenty of .NET support for it. CodePlex hosts two related projects: Facebook.NET, which provides a .NET library for use in developing Facebook applications and accessing Facebook APIs, and Facebook Developer Toolkit which was initially developed by Clarity Consulting Inc.. Jay Lagorio has written a Facebook wrapper for VB.NET, and fbasync is a CodePlex project focused on asynchronous API for Facebook. 

Google and YouTube

Google's API, named GData, is a comprehensive set of libraries for communication using XML over HTTP. GData is serving YouTube, Blogger, Google Calendar, Notebook, Spreadsheets, Documents, Picassa, etc. Google has provided a wrapper for .NET developers, so they can read and write GData content quite easily, like in the following example provided by Google in the .NET Developer's Guide:

AtomEntry newPost = new AtomEntry();
newPost.Title.Text = "Marriage!";
newPost.Content = new AtomContent();
newPost.Content.Content = "<div xmlns='http://www.w3.org/1999/xhtml'>" +
"<p>Mr. Darcy has <em>proposed marriage</em> to me!</p>" +
"<p>He is the last man on earth I would ever desire to marry.</p>" +
"<p>Whatever shall I do?</p>" +
"</div>";
newPost.Content.Type = "xhtml";
newPost.Authors.Add(new AtomPerson());
newPost.Authors[0].Name = "Elizabeth Bennet";
newPost.Authors[0].Email = "liz@gmail.com";

AtomEntry createdEntry = service.Insert("http://www.blogger.com/feeds/" + blogId + "/posts/default", newPost);

For more information and many other libraries available for various Web 2.0 services, Scott Hanselman's post is a good starting point.

Rate this Article

Adoption
Style

BT