因此,我谦卑地寻求有关如何将已经转换的C#转换为VB代码的帮助 到Windows窗体版本。谢谢。
Namespace GoogleDriveSamples
Class DriveCommandLineSample
Private Shared Sub Main(args As String())
Dim credential As UserCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets() With { _
Key .ClientId = "CLIENT_ID_HERE", _
Key .ClientSecret = "CLIENT_SECRET_HERE" _
}, New () {DriveService.Scope.Drive}, "user", CancellationToken.None).Result
' Create the service.
Dim service = New DriveService(New BaseClientService.Initializer() With { _
Key .HttpClientInitializer = credential, _
Key .ApplicationName = "Drive API Sample" _
})
Dim body As New File()
body.Title = "My document"
body.Description = "A test document"
body.MimeType = "text/plain"
Dim byteArray As Byte() = System.IO.File.ReadAllBytes("document.txt")
Dim stream As New System.IO.MemoryStream(byteArray)
Dim request As FilesResource.InsertMediaUpload = service.Files.Insert(body, stream, "text/plain")
request.Upload()
Dim file As File = request.ResponseBody
Console.WriteLine("File id: " + file.Id)
Console.WriteLine("Press Enter to end this process.")
Console.ReadLine()
End Sub
End Class
End Namespace
答案 0 :(得分:0)
云端硬盘SDK(或任何其他谷歌SDK)目前不支持vb。使用c#/ .net这样做,或者如果必须,可以直接从任何语言执行https调用(直接获取帖子等),甚至vb。
答案 1 :(得分:0)
Option Infer On
Imports System.Threading
Imports System.Threading.Tasks
Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Drive.v2
Imports Google.Apis.Drive.v2.Data
Imports Google.Apis.Services
Public Class Form1
Private Sub btnUpload_Click(sender As Object, e As EventArgs) Handles btnUpload.Click
Dim secrets = New ClientSecrets()
secrets.ClientId = "CLIENT_ID_HERE"
secrets.ClientSecret = "CLIENT_SECRET_HERE"
Dim scope = New List(Of String)
scope.Add(DriveService.Scope.Drive)
Dim credential = GoogleWebAuthorizationBroker.AuthorizeAsync(secrets, scope, "user", CancellationToken.None).Result()
Dim initializer = New BaseClientService.Initializer
initializer.HttpClientInitializer = credential
initializer.ApplicationName = "Drive API Sample"
Dim service = New DriveService(initializer)
Dim body = New File
body.Title = "My document"
body.Description = "A test document"
body.MimeType = "text/plain"
Dim byteArray = System.IO.File.ReadAllBytes("C:\MyFile.txt")
Dim stream = New System.IO.MemoryStream(byteArray)
Dim request = service.Files.Insert(body, stream, "text/plain")
request.Upload()
body = request.ResponseBody
MessageBox.Show("The File id is:" & body.Id, "Upload Succeeded")
End Sub
End Class