vb.net 无法将我的文件上传到 google 驱动器

vb.net can't upload my file in google drive

我正在使用 google 驱动器 api 上传 pdf 文件(使用 vb.net),我在这个网站和另一个网站上搜索了很多教程(如何获取 google drive api in vb.net , 如何上传...) 最后我成功完成了 但问题是,没有文件添加到驱动器

这是我的代码

Private Sub btn_save_Click(sender As Object, e As EventArgs) Handles btn_save.Click
    Dim filename As String = fichier.FileName 'from selected file in openfiledialog
    CreateService()
    UploadFile(filename)
End Sub


Private Service As DriveService = New DriveService

Private Sub CreateService()

    Dim ClientId = "*********"
    Dim ClientSecret = "****************"
    Dim MyUserCredential As UserCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets() With {.ClientId = ClientId, .ClientSecret = ClientSecret}, {DriveService.Scope.Drive}, "user", CancellationToken.None).Result
    Service = New DriveService(New BaseClientService.Initializer() With {.HttpClientInitializer = MyUserCredential, .ApplicationName = "Google Drive VB Dot Net"})
End Sub
Private Sub UploadFile(FilePath As String)
    Me.Cursor = Cursors.WaitCursor
    CreateService()
    Dim ByteArray As Byte() = System.IO.File.ReadAllBytes(FilePath)
    Dim Stream As New System.IO.MemoryStream(ByteArray)
    Me.Cursor = Cursors.Default
    MsgBox("Upload Finished")
End Sub

当我执行我的应用程序时,结果是

但我在驱动器中找不到任何文件

您调用了两次 CreateService() 但从未使用它上传任何内容。

Private Sub UploadFile(FilePath As String)
    Me.Cursor = Cursors.WaitCursor
    CreateService()
    Dim ByteArray As Byte() = System.IO.File.ReadAllBytes(FilePath)
    Dim Stream As New System.IO.MemoryStream(ByteArray)
    '' ---------------------------------------------------------
    '' Here you'll going to use the service to upload your data
    '' with Service.Files.Create()
    '' ---------------------------------------------------------
    Me.Cursor = Cursors.Default
    MsgBox("Upload Finished")
End Sub