0
我很努力從Google雲端硬盤獲取數據。谷歌REST API下載
我使用谷歌雲端硬盤API V3使用此代碼:
Imports System.Security.Cryptography.X509Certificates
Imports System
Imports System.Threading
Imports System.Threading.Tasks
Imports System.IO
Imports System.Linq
Imports System.Text
Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Drive.v3
Imports Google.Apis.Drive.v3.Data
Imports Google.Apis.Services
Imports Google.Apis.Util.Store
Public Class DownloadMe
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub btn0_Click(sender As Object, e As EventArgs) Handles btn0.Click
DownloadMe()
End Sub
Protected Sub DownloadMe()
Dim fileID As String = "someFileID"
Dim driveService As New DriveService
Dim request = driveService.Files.Export(fileID, "text/plain")
'Dim request = driveService.Files.Get(fileID)
Dim dir As String = "C:\Users\JohnDoe\Documents\Visual Studio 2012\Projects\GoogleDriveDownload\"
Dim output As String = dir + "test.txt"
Dim stream As New System.IO.MemoryStream
Try
request.Download(stream)
If System.IO.File.Exists(output) Then
System.IO.File.Delete(output)
End If
Dim fs As New FileStream(output, FileMode.Create, FileAccess.Write)
stream.WriteTo(fs)
stream.Close()
fs.Close()
Catch ex As Exception
MyCompany.Diagnostics.Log("An error occured: " + ex.Message)
lit0.Text = "An error occured: " + ex.Message + "<br />"
End Try
End Sub
End Class
問題是我得到什麼流中,因此創造了「的text.txt」文件是空白的文件,而不是典型的「Lorem ipsum ...」文本。
任何線索如何彌補這一點?