从Google驱动器下载文件

问题描述 投票:0回答:1

我正在尝试从Google驱动器中下载文件。我检查了这两个示例,但没有一个适合我:

  Sub DownloadPDF()
Dim FileNum As Long
Dim FileData() As Byte
Dim MyFile As String
Dim WHTTP As Object

On Error Resume Next
    Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
    If Err.Number <> 0 Then
        Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
    End If
On Error GoTo 0

MyFile = "https://docs.google.com/a/dink.eu/file/d/0B2P4BoDG6mdejjesiEEFMNHN0cFU/edit?usp=sharing"

WHTTP.Open "GET", MyFile, False
WHTTP.send
FileData = WHTTP.ResponseBody
Set WHTTP = Nothing

If Dir("C:\MyDownloads", vbDirectory) = Empty Then MkDir "C:\MyDownloads"

FileNum = FreeFile
Open "C:\MyDownloads\binder.pdf" For Binary As #FileNum
    Put #FileNum, 1, FileData
Close #FileNum

MsgBox "Open the folder [ C:\MyDownloads ] for the downloaded file..."
End Sub

第二个例子:

 Private Declare Function URLDownloadToFile _
 Lib "urlmon" _
 Alias "URLDownloadToFileA" _
 ( _
     ByVal pCaller As Long, _
     ByVal szURL As String, _
     ByVal szFileName As String, _
     ByVal dwReserved As Long, _
     ByVal lpfnCB As Long _
 ) As Long



 Sub DownPDF()

Dim ss As String
Dim ts As String
ss = "https://docs.google.com/a/dink.eu/file/d/0B46Ux_7O0o-4RdefsERgaEHU2YtZXM/edit?pli=1"
ts = "c:\MyDownloads\Stryker experience binder.pdf"
URLDownloadToFile 0, ss, ts, 0, 0

End Sub

使用普通链接,例如,如果我使用以下链接http://www.bigfoto.com/sites/main/tree-winter-xxx.JPG,则它们可以正常工作,但使用Google Drive链接则不能。如何使它与Google云端硬盘链接一起使用?

我正在尝试从Google驱动器中下载文件。我检查了这两个示例,但没有一个适合我:Sub DownloadPDF()Dim FileNum as Long Dim FileData()As Byte Dim MyFile As String Dim ...

vba download google-drive-api
1个回答
-1
投票

在第一个示例中尝试使用此链接格式:

© www.soinside.com 2019 - 2024. All rights reserved.