现在的位置: 首页 > 综合 > 正文

谷歌发布.NET平台YouTube SDK

2012年05月07日 ⁄ 综合 ⁄ 共 1363字 ⁄ 字号 评论关闭

    谷歌发布的这个.NET SDK,意味着对微软开发平台的支持与承认。将更方便.NET程序员在YouTube的程序开发工作。

    近日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:

  1. YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", YTCLIENTID, YTDEVKEY); 
  2. YouTubeRequest f = new YouTubeRequest(settings); 
  3. settings.AutoPaging = true; 
  4. settings.Maximum = 200; //only 75 come back but that is a feature 
  5. Feed<Video> sfeed = f.GetStandardFeed(YouTubeQuery.MostPopular); 
  6. //put the entire list into a list. 
  7. var entries = sfeed.Entries.ToList(); 
  8. var oneHunderTitles = from e in entries 
  9.                       where e.ViewCount > 100 
  10.                       where e.Rating > 2 
  11.                       where e.Updated < new DateTime(2008, 12, 4) 
  12.                       orderby e.Rating descending 
  13.                       orderby e.Title 
  14.                       select e; 
  15.  
  16. foreach (var item in oneHunderTitles) { 
  17.     Console.WriteLine(item.Title); 
  18. //here is an inline orderby on title as a lambda 
  19. foreach (var item in entries.OrderBy(i => i.Title)) { 
  20.     Console.WriteLine(item.Title); 
  21. Console.WriteLine(sfeed.Entries.Count());

抱歉!评论已关闭.