近日 Google发布了.NET 版的YouTube SDK (MSI),以此满足那些希望从.NET 或ASP.NET 应用中以编程的方式访问YouTube 的开发者的需要。
该SDK 包含了一个YouTube API 的 CHM 帮助文件,一个 Visual Studio 2008 模板和几个用于说明 API 用法的应用示例:可以将视频文件上传到 YouTube 上的工具、使用了 AuthSub 的 ASP.NET 迷你站点、由 YouTube 支持的授权服务以及当用户在 YouTube 上有新动作时会自动发出通知的应用。
YouTube API 构建在 Google 的 GData 协议之上(MSI),并通过 Google.GData.YouTube 命名空间中特定的数据类对其进行了扩展。 GData 是个面向 Web 通讯的开源协议,为 Google 的众多服务所广为使用,如 Blogger、Calendar、Picasa 以及 YouTube 等等。
下面的代码示例取自 SDK 的帮助文档,展示了如何通过 LINQ 的链式 where 从句来访问 YouTube:
YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", YTCLIENTID, YTDEVKEY);
YouTubeRequest f = new YouTubeRequest(settings);
settings.AutoPaging = true;
settings.Maximum = 200; //only 75 come back but that is a feature
Feed<Video> sfeed = f.GetStandardFeed(YouTubeQuery.MostPopular);
//put the entire list into a list.
var entries = sfeed.Entries.ToList();
var oneHunderTitles = from e in entries
where e.ViewCount > 100
where e.Rating > 2
where e.Updated < new DateTime(2008, 12, 4)
orderby e.Rating descending
orderby e.Title
select e;
foreach (var item in oneHunderTitles) {
Console.WriteLine(item.Title);
}
//here is an inline orderby on title as a lambda
foreach (var item in entries.OrderBy(i => i.Title)) {
Console.WriteLine(item.Title);
}
Console.WriteLine(sfeed.Entries.Count());




