在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
[阅读全文...]
挖客还挖到了什么 · · · · · ·