2016-05-16 67 views
3

我需要使用YouTube API V3如何使用Youtube API查找实况视频列表?

来自任何渠道的现场活动列表我加入了官方的NuGet包到我的WPF项目:

使用Google.Apis.Auth.OAuth2;使用Google.Apis.Services的 ; 使用Google.Apis.Util.Store; 使用Google.Apis.YouTube.v3;

和我在一个按钮,点击添加OAuth认证:

UserCredential credential; 
    using (var stream = new FileStream("mydowloadedjsonfile.json", FileMode.Open, FileAccess.Read)) 
    { 
     credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
      GoogleClientSecrets.Load(stream).Secrets, new[] { YouTubeService.Scope.YoutubeReadonly }, "user", 
      CancellationToken.None, new FileDataStore("YouTubeAPI") 
      ).Result; 
    } 

    var service = new YouTubeService(new BaseClientService.Initializer() 
    { 
     HttpClientInitializer = credential, 
     ApplicationName = "YouTubeAPI" 
    }); 

此代码的伟大工程,它会打开一个浏览器来得到验证,并允许YouTube的权限,以我的用户

之后,我想拿到现场活动的清单,但我failling:

 var request = service.Search.List("snippet"); 
     request.Q = "live event";//I know this is wrong... 
     request.MaxResults = 10; 
     var response = request.Execute(); 

东北角我做错了,可有人指向正确的方向吗?

回答

1

我找到了答案通过此请求,而不是:需要

 var request = service.Search.List("snippet"); 
     request.Q = txtSearch.Text.Trim(); 
     request.EventType = SearchResource.ListRequest.EventTypeEnum.Live; 
     request.Type = "video"; 
     request.MaxResults = 10; 

request.Type否则你将得到谷歌的例外。 Api开发人员让它变得丑陋......它正在乞求成为一个枚举或东西

相关问题