从谷歌驱动器下载文件 [英] download file from google drive

查看:246
本文介绍了从谷歌驱动器下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从谷歌驱动器中载入一个文件。我检查这两个例子,但没有人适用于我:

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

On Error Resume Next
设置WHTTP = CreateObject(WinHTTP.WinHTTPrequest .5)
如果Err.Number<> 0然后
设置WHTTP = CreateObject(WinHTTP.WinHTTPrequest.5.1)
结束如果
错误GoTo 0

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

WHTTP.OpenGET,MyFile,False
WHTTP.send
FileData = WHTTP.ResponseBody
设置WHTTP =没有

如果Dir(C:\MyDownloads,vbDirectory)=空然后MkDirC:\MyDownloads

FileNum = FreeFile
打开C:\MyDownloads\binder.pdf对于二进制为#FileNum
放置#FileNum,1,FileData
关闭#FileNum

MsgBox打开下载文件的文件夹[C:\MyDownloads] ...
End Sub

第二个例子:

 私有声明函数URLDownloadToFile _ 
Liburlmon _
别名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 它的工作原理完美,但与谷歌驱动器链接没有。如何使用谷歌驱动器链接工作?

解决方案

尝试在第一个示例中使用此链接格式:
https://docs.google.com/uc?export=download& id = 0B2P4BoDG6mdejjesiEEFMNHN0cFU



更多帮助:
http://thebiobucket.blogspot.hu/2011/10/how-to-link-to-google-docs-for- download.html


I am trying to donwload a file from google drive. I check for these two examples but no one works for me:

  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

The second example:

 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

With normal links they works for example if I use the following link http://www.bigfoto.com/sites/main/tree-winter-xxx.JPG it works perfectly but with google drive links it doesn't. How can I do to make it work with google drive links?

解决方案

Try to use this link format in the first example: https://docs.google.com/uc?export=download&id=0B2P4BoDG6mdejjesiEEFMNHN0cFU

more help: http://thebiobucket.blogspot.hu/2011/10/how-to-link-to-google-docs-for-download.html

这篇关于从谷歌驱动器下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆