mth*_*ult 9 .net google-drive-api
对于所有Google文档,我无法从通过文件响应返回的ThumbnailLink属性下载缩略图图像.
我总是收到一个'403 - Forbidden'错误页面,其中包含类似这样的消息:
您的客户端无权从此服务器获取URL/thumbnailLink.
(客户端IP地址:clientIP)
未授权用户
我尝试使用Google提供的MediaDownloader.cs类,我也尝试使用以下代码下载它:
using (Stream stream = service.HttpClient.GetStreamAsync(p_DownloadUrl).Result) {
StreamUtilities.Copy(p_WriteDelegate, stream.Read);
}
Run Code Online (Sandbox Code Playgroud)
其中'service'是正确实例化的DriveService(IClientService)对象.我可以用它来下载文件或提出任何其他请求.我使用'Drive.Readonly'范围.
我没有任何问题下载Word,Excel,PDF等文档的缩略图,因为这些链接是公开的,不需要任何类型的身份验证.
我做错了什么?
是否可以下载Google Docs文档的缩略图?
小智 1
我们最近进行了更改来解决此问题。请重试您的代码,看看是否仍然出现此错误。我能够运行以下代码来成功下载我的 Google 文档的缩略图。
# 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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1369 次 |
| 最近记录: |