Я пытаюсь преобразовать пример «поиск по ключевому слову» на странице разработчиков Google в vb. Я получаю несколько ошибок, которые я не могу исправить. https://developers.google.com/youtube/v3/code_samples/dotnet#search_by_keyword
Imports System.Collections.Generic
Imports System.IO
Imports System.Reflection
Imports System.Threading
Imports System.Threading.Tasks
Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Services
Imports Google.Apis.Upload
Imports Google.Apis.Util.Store
Imports Google.Apis.YouTube.v3
Imports Google.Apis.YouTube.v3.Data
Namespace Google.Apis.YouTube.Samples
' <summary>
' YouTube Data API v3 sample: search by keyword.
' Relies on the Google APIs Client Library for .NET, v1.7.0 or higher.
' See https://code.google.com/p/google-api-dotnet-client/wiki/GettingStarted
'
' Set ApiKey to the API key value from the APIs & auth > Registered apps tab of
' https://cloud.google.com/console
' Please ensure that you have enabled the YouTube Data API for your project.
' </summary>
Friend Class Search
<STAThread()> _
Private Shared Sub Main(args As String())
Console.WriteLine("YouTube Data API: Search")
Console.WriteLine("========================")
Try
New Search().Run().Wait()
Catch ex As AggregateException
For Each e In ex.InnerExceptions
Console.WriteLine("Error: " & e.Message)
Next
End Try
Console.WriteLine("Press any key to continue...")
Console.ReadKey()
End Sub
Private Function Run() As Task
Dim youtubeService = New YouTubeService(New BaseClientService.Initializer() With { _
.ApiKey = "REPLACE_ME", _
.ApplicationName = Me.[GetType]().ToString() _
})
Dim 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.
Dim searchListResponse = Await searchListRequest.ExecuteAsync()
Dim videos As New List(Of String)()
Dim channels As New List(Of String)()
Dim playlists As New List(Of String)()
' Add each result to the appropriate list, and then display the lists of
' matching videos, channels, and playlists.
For Each searchResult In SearchListResponse.Items
Select Case searchResult.Id.Kind
Case "youtube#video"
videos.Add([String].Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.VideoId))
Exit Select
Case "youtube#channel"
channels.Add([String].Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.ChannelId))
Exit Select
Case "youtube#playlist"
playlists.Add([String].Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.PlaylistId))
Exit Select
End Select
Next
Console.WriteLine([String].Format("Videos:" & vbLf & "{0}" & vbLf, String.Join(vbLf, videos)))
Console.WriteLine([String].Format("Channels:" & vbLf & "{0}" & vbLf, String.Join(vbLf, channels)))
Console.WriteLine([String].Format("Playlists:" & vbLf & "{0}" & vbLf, String.Join(vbLf, playlists)))
End Function
End Class
End Namespace
«Синтаксическая ошибка» возникает по адресу:
Try
New Search().Run().Wait()
«Ожидается конец оператора» происходит по адресу:
Dim searchListResponse = Await searchListRequest.ExecuteAsync()
«Ссылка на неразделяемый элемент требует ссылки на объект» возникает по адресу:
For Each searchResult In SearchListResponse.Items
Спасибо