谷歌驱动器 - 无法下载缩略图的认证(OAuth2)要求 [英] Google Drive - Unable to download thumbnails with an authenticated (OAuth2) request
问题描述
对于所有谷歌文档,我不能够从一个文件响应返回ThumbnailLink属性下载缩略图。
For all Google Docs, I'm not able to download the thumbnail image from the ThumbnailLink property returned with a file response.
我总是收到一个403 - 禁止的错误页面,类似这样的消息:
I always receive a '403 - Forbidden' error page with a message similar to this:
您的客户无权获得网址/ thumbnailLink 从该服务器。
Your client does not have permission to get URL /thumbnailLink from this server.
(客户端IP地址: clientIP )
Unuthorized用户
Unuthorized User
我尝试使用这个类的 MediaDownloader.cs 的由谷歌提供的,我也尝试使用这个code下载吧:
I try to use the class MediaDownloader.cs provided by Google and I also try to download it by using this code:
using (Stream stream = service.HttpClient.GetStreamAsync(p_DownloadUrl).Result) {
StreamUtilities.Copy(p_WriteDelegate, stream.Read);
}
其中'服务'是一个DriveService(IClientService)对象的正确实例。我可以用它来下载文件,或进行任何其他请求。我用的是'Drive.Readonly范围。
where 'service' is a DriveService (IClientService) object properly instantiated. I can use it to download the file or make any other requests. I use the 'Drive.Readonly' scope.
我没有任何问题,下载缩略图了的Word,Excel,PDF等文档,因为这些链接是公开的,不需要任何种类的认证。
I didn't have any issue to download the Thumbnail for a Word, Excel, PDF, etc. documents, because these links are public and doesn't require any kind of authentication.
我不正确吗?
是否可以下载缩略图的谷歌文档文件?
Is it possible to download the thumbnail for a Google Docs document?
推荐答案
我们最近做了一个改变来解决这个问题。请再次尝试你的code,看看你仍然得到这个错误。我能够运行下面的code成功下载我的谷歌文档的缩略图。
We've recently made a change to fix this issue. Please try your code again and see if you are still getting this error. I was able to run the following code to successfully download a thumbnail of my Google Document.
# Get oauth credentials
...
# Authorize an http object
http = httplib2.Http()
http = credentials.authorize(http)
drive_service = build('drive', 'v2', http=http)
# Google Document type ID
docId = '1ns9x5BMIZAeUR-eXerqgpaHBBGkl_-_KCVpVoV5opn8'
files = drive_service.files().get(fileId=docId).execute()
thumbnailLink = files['thumbnailLink']
print 'Downloading thumbnail at: ', thumbnailLink
response, content = http.request(thumbnailLink)
print response.status
with open('thumbnail.jpg', 'wb') as f:
f.write(content)
这篇关于谷歌驱动器 - 无法下载缩略图的认证(OAuth2)要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!