Google Drive - Unable to download thumbnails with an authenticated (OAuth2) request

前端 未结 3 2069
一生所求
一生所求 2020-12-31 15:12

For all Google Docs, I\'m not able to download the thumbnail image from the ThumbnailLink property returned with a file response.

I always receive a \'403 - Forbidde

3条回答
  •  失恋的感觉
    2020-12-31 15:32

    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)
    

提交回复
热议问题