問題描述
對于所有 Google 文檔,我無法從文件響應返回的 ThumbnailLink 屬性下載縮略圖.
For all Google Docs, I'm not able to download the thumbnail image from the ThumbnailLink property returned with a file response.
我總是收到403 - Forbidden"錯誤頁面,其中包含類似以下的消息:
I always receive a '403 - Forbidden' error page with a message similar to this:
您的客戶端無權從該服務器獲取 URL/thumbnailLink.
Your client does not have permission to get URL /thumbnailLink from this server.
(客戶端IP地址:clientIP)
未經授權的用戶
我嘗試使用谷歌提供的類MediaDownloader.cs,我也嘗試使用以下代碼下載它:
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.
我做錯了什么?
是否可以下載 Google Docs 文檔的縮略圖?
Is it possible to download the thumbnail for a Google Docs document?
推薦答案
我們最近進行了更改以解決此問題.請再次嘗試您的代碼,看看您是否仍然收到此錯誤.我能夠運行以下代碼來成功下載我的 Google 文檔的縮略圖.
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)
這篇關于Google 云端硬盤 - 無法通過經過身份驗證的 (OAuth2) 請求下載縮略圖的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!