【发布时间】:2018-09-17 11:40:08
【问题描述】:
我正在尝试使用 Winforms 应用收集 YouTube 视频的数据。当我如下所示调用YTSearch() 方法时,程序在到达时停止响应
var slResponse = await slRequest.ExecuteAsync();
请求已启动,但并未停止,也未完成,也未在 try catch 上触发 catch。我已经设法使用 Discord 机器人,使用 Discord.NET 来实现完全相同的工作。在输出中是
抛出异常:Google.Apis.dll 中的“Google.GoogleApiException”
抛出异常:mscorlib.dll 中的“Google.GoogleApiException”
抛出异常:mscorlib.dll 中的“Google.GoogleApiException”
库:
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
using Google.Apis.YouTube.v3;
using Google.Apis.Services;
using System.Diagnostics;
方法:
public async Task<List<Video>> YTSearch(string query)
{
string ytAPI = APIKEY; // Ommitted
var ytService = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = ytAPI,
ApplicationName = "YouTubeDownloader"
});
var slRequest = ytService.Search.List("snipper");
slRequest.Q = query;
slRequest.MaxResults = 10;
var slResponse = await slRequest.ExecuteAsync();
List<Video> vidList = new List<Video>();
return vidList;
}
致电:
private void btnSearch_Click(object sender, EventArgs e)
{
List<Video> vidList = YTSearch(txtSearch.Text).Result;
}
【问题讨论】:
标签: c# google-api youtube-api youtube-data-api google-api-dotnet-client