不兼容Windows窗体应用程序
问题描述:
我想制作一个程序,使用YouTube数据API,v3在YouTube上搜索视频,我拥有密钥和访问权限,但是我在Visual Studio 2013中使用了Windows窗体中的Vb.net,发现任何示例只是帮助控制台,但没有帮助。不兼容Windows窗体应用程序
例子:http://pastebin.com/K5LiYnje和http://pastebin.com/GEtKfiA6
帮助
答
YouTube数据API,您可以请求一组的匹配特定搜索词的视频。该API支持各种标准的Google数据查询参数以及与视频搜索特别相关的自定义参数。
要执行搜索请求,您需要创建一个YouTubeQuery对象来指定您的搜索条件并将该对象传递给YouTubeRequest.Get()方法。
在客户端库代码中,Query类和YouTubeQuery等子类负责构建供稿网址。在上面的例子中的YouTubeQuery对象构造以下供稿网址:
这里是它采用.NET平台上的示例代码段:
var searchListRequest = youtubeService.Search.List("snippet");
searchListRequest.Q = "Google"; // Replace with your search term.
searchListRequest.MaxResults = 50;
// Call the search.list method to retrieve results matching the specified query term.
var searchListResponse = await searchListRequest.ExecuteAsync();
List<string> videos = new List<string>();
List<string> channels = new List<string>();
List<string> playlists = new List<string>();
// Add each result to the appropriate list, and then display the lists of
// matching videos, channels, and playlists.
foreach (var searchResult in searchListResponse.Items)
{
switch (searchResult.Id.Kind)
{
case "youtube#video":
videos.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.VideoId));
break;
case "youtube#channel":
channels.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.ChannelId));
break;
case "youtube#playlist":
playlists.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.PlaylistId));
break;
}
}
有关如何检索搜索结果的完整代码,检查:https://developers.google.com/youtube/v3/code_samples/dotnet#search_by_keyword
我试过这个http://pastebin.com/CmcmtnhM,但我得到了2个错误“搜索”不是“Google.GData.YouTube.YouTubeService”的成员,而“类型'var'未定义。” – Ranieri