拼吾爱程序人生

首页 » .Net编程 » C# » C# and VB .NET Libraries to Google, and other Web 2.0 APIs
cobra - 2008-4-4 1:18:00
Posted by Abel Avram  From/InfoQ

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.
DiggDigg'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));
    }
}
FacebookFacebook 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 YouTubeGoogle'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.C +
  "<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.

 您可能对 [C#] 的这些文章也感兴趣:

论C#变得越来越臃肿是不可避免的
查询IP所在区段(C#)
在C#中利用SharpZipLib进行文件的压缩和解压缩
C# - Append a host header by code in IIS
在C#中调用Microsoft.VisualBasic命名空间下的类型验证函数
使用泛型实现单例提供者(原创翻译)
C#2 anonymous methods
Master Pages: Tips, Tricks, and Traps
Microsoft .NET 框架资源基础
基于.Net平台应用程序唯一运行实例实现
.net Framework 2.0 专门提供了配置文件的操作
正确实现 IDisposable
cobra - 2008-4-11 8:40:00
面向Google、YouTube、Facebook以及其他Web 2.0 API的C#和VB.NET类库

译/赵劼

在Scott Hanselman博客最近发表的一篇文章中,Scott编辑了一系列.NET类库,这些类库有助于开发人员面向那些互联网上著名的Web 2.0 API进行开发。

Digg

Digg的API使用REST形式的接口,并且通过XML进行通信。DiggApiNet是Digg API的一个.NET封装。CodeProject还包括另一个可用的API封装Digg API.NET。在Hanselman提供的如下示例中,从一个特定的URL中创建和加载了一个XmlDocument对象,然后将XML节点复制到Digg的特定对象中。



引用:
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

Fackbook提供了一个复杂的API,目前已经可以获得足够多的.NET支持。CodePlex托管了两个相关的项目:一个是Facebook.NET,它提供了一套用于开发Facebook应用程序以及访问Fackbook API的.NET类库;另一个则是Facebook Developer Toolkit,最初由Clarity Consulting Inc.开发。Jay Lagorio为VB.NET编写了一个Facebook的API封装,而fbasync则是一个面向Fackbook异步API的CodePlex项目。

Google and YouTubeGoogle的API“GData” 是一套全面的类库,使用了XML并基于HTTP协议实现通信。GData为YouTube、Blogger、Google Calendar、Notebook、Spreadsheets、Documents、Picassa等提供支持。Google为.NET开发人员提供了 一个封装,以便于他们快捷地读写GData内容。以下示例撷取自Google提供的.NET开发人员指南



引用:
AtomEntry newPost = new AtomEntry();
newPost.Title.Text = "Marriage!";
newPost.Content = new AtomContent();
newPost.Content.C +
  "<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);
如果您想了解更多有关各种Web 2.0服务的类库,从Scott Hanselman的文章出发会是一个不错的选择。
1
查看完整版本: C# and VB .NET Libraries to Google, and other Web 2.0 APIs
Modify by pin5i DZNT_ExpandPackage 2.1.3295 2007-2009 pin5i.com
 Total Unique Visitors: