所以我找到了使用v3 API将视频上传到YouTube的C#示例,但我想知道VB.NET中是否有任何代码示例。我实际上试图从C#转换为VB.NET,这就是我想到的:
Namespace Google.Apis.YouTube.Samples
''' <summary>
''' YouTube Data API v3 sample: upload a video.
''' 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
''' </summary>
Friend Class UploadVideo
<STAThread> _
Private Shared Sub Main(args As String())
Console.WriteLine("YouTube Data API: Upload Video")
Console.WriteLine("==============================")
Try
New UploadVideo().Run().Wait()
Catch ex As AggregateException
For Each e As var 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 credential As UserCredential
Using stream = New FileStream("client_secrets.json", FileMode.Open, FileAccess.Read)
' This OAuth 2.0 access scope allows an application to upload files to the
' authenticated user's YouTube channel, but doesn't allow other types of access.
credential = Await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, New () {YouTubeService.Scope.YoutubeUpload}, "user", CancellationToken.None)
End Using
Dim youtubeService__1 = New YouTubeService(New BaseClientService.Initializer() With { _
Key .HttpClientInitializer = credential, _
Key .ApplicationName = Assembly.GetExecutingAssembly().GetName().Name _
})
Dim video = New Video()
video.Snippet = New VideoSnippet()
video.Snippet.Title = "Default Video Title"
video.Snippet.Description = "Default Video Description"
video.Snippet.Tags = New String() {"tag1", "tag2"}
video.Snippet.CategoryId = "22"
' See https://developers.google.com/youtube/v3/docs/videoCategories/list
video.Status = New VideoStatus()
video.Status.PrivacyStatus = "unlisted"
' or "private" or "public"
Dim filePath = "REPLACE_ME.mp4"
' Replace with path to actual movie file.
Using fileStream = New FileStream(filePath, FileMode.Open)
Dim videosInsertRequest = youtubeService__1.Videos.Insert(video, "snippet,status", fileStream, "video/*")
AddHandler videosInsertRequest.ProgressChanged, AddressOf videosInsertRequest_ProgressChanged
AddHandler videosInsertRequest.ResponseReceived, AddressOf videosInsertRequest_ResponseReceived
Await videosInsertRequest.UploadAsync()
End Using
End Function
Private Sub videosInsertRequest_ProgressChanged(progress As Google.Apis.Upload.IUploadProgress)
Select Case progress.Status
Case UploadStatus.Uploading
Console.WriteLine("{0} bytes sent.", progress.BytesSent)
Exit Select
Case UploadStatus.Failed
Console.WriteLine("An error prevented the upload from completing." & vbLf & "{0}", progress.Exception)
Exit Select
End Select
End Sub
Private Sub videosInsertRequest_ResponseReceived(video As Video)
Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id)
End Sub
End Class
结束命名空间
“============================================== ========= 'Telerik提供的服务(www.telerik.com) '转换由NRefactory提供支持。 'Twitter:@telerik 'Facebook:facebook.com/telerik “================================================= ==
我想知道是否有人能帮助我解决以下问题:
如何将此代码从C#转换为VB.NET(如果在上例中不正确)。
如果有人可以帮我找到合适的v3 API .DLL文件,我需要在VB.NET中添加引用。
如果有人可以帮助授权令牌。在哪里创建这些令牌。
我非常感谢你的帮助!
YouTube API,YouTube上传API
答案 0 :(得分:0)
This is a VB .NET example that I developed. It is configured for .NET 4.0.
http://www.codeproject.com/Tips/801604/Sample-VB-NET-program-using-Google-APIs-for-NET-V