在 VB.NET 中使用 Google YouTube Data API 获取 YouTube 频道数据 [英] Get YouTube channel data using Google YouTube Data API in VB.NET
问题描述
我想在 VB.NET 应用程序中使用 YouTube 数据 API 获取频道数据.我找不到任何类型的文档,所有内容都在 .NET 中,而 Google 文档对我来说太神秘了.我曾经使用 URL 请求获取这些数据,但我想以编程方式做更多的事情!我添加了 Google.Apis.YouTube.v3 Nuget,但不知道如何设置凭据和检索数据.
I'd like to get channel data using the YouTube Data API in a VB.NET application. I can't find any kind of documentation, everything is in .NET and Google documentation is way too cryptic for me. I used to get these data using URL request, but I'd like to do it more... programmatically! I added Google.Apis.YouTube.v3 Nuget, but can't figure how to set credential and retrieve data.
推荐答案
我做到了,感谢 Mike Meinz 和 Visual Studio 调试工具这里是在 VB.NET 中使用 YouTube Data API 获取一些频道(不是你的)数据的代码:
I did it, thanks to Mike Meinz and th Visual Studio debugging tools Here the code to get some channels (not necessary yours) data using YouTube Data API in a VB.NET:
Dim youtube_api_key As String = "Your_Key"
Dim youtube_api_application_name As String = "Your_Project_Name_In_the_Google_Developper_Console"
Dim youtube_initialiser As New Google.Apis.Services.BaseClientService.Initializer()
youtube_initialiser.ApiKey = youtube_api_key
youtube_initialiser.ApplicationName = youtube_api_application_name
Dim youtube_service As Google.Apis.YouTube.v3.YouTubeService = New YouTubeService(youtube_initialiser)
Dim objChannelListRequest As ChannelsResource.ListRequest = youtube_service.Channels.List("id,snippet,statistics")
objChannelListRequest.Id = youtube_channel
Dim objChannelListResponse As ChannelListResponse = objChannelListRequest.Execute()
Debug.Print(objChannelListResponse.Items(0).Snippet.Description)
Debug.Print(objChannelListResponse.Items(0).Statistics.SubscriberCount)
Debug.Print(objChannelListResponse.Items(0).Statistics.VideoCount)
Debug.Print(objChannelListResponse.Items(0).Statistics.ViewCount)
这篇关于在 VB.NET 中使用 Google YouTube Data API 获取 YouTube 频道数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!