【IT168 评论】近日Google发布了.NET版的YouTube SDK(MSI),以此满足那些希望从.NET或ASP.NET应用中以编程的方式访问YouTube的开发者的需要。谷歌发布的这个.NET SDK,意味着对微软开发平台的支持与承认。将更方便.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());
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());