2017-07-20 154 views
-1

我使用谷歌驅動器api上傳PDF文件(與vb.net),我搜索了很多教程在這個和另一個網站(如何獲得谷歌驅動器API在vb.net中,如何上傳...),最後我已經成功做到了 但問題,沒有文件在傳動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 

當我執行我的應用程序,結果是

enter image description here

但我找不到驅動器中的任何文件

回答

2

您正在調用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 
+0

插入不固定fileresource –

+0

的一員,與V3將使用Files.Create() –

+0

我很堅持,我如何使用它V2 API(舉個例子) –

相關問題