第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Google 云端硬盤縮略圖鏈接返回 404

Google 云端硬盤縮略圖鏈接返回 404

ibeautiful 2023-05-16 09:49:46
這種獲取 Google 云端硬盤文件縮略圖的方法對我一直有效,但最近似乎已停止。我可以在網(wǎng)上找到的所有答案都表明這是因?yàn)?thumbnailLink 需要授權(quán)(例如)。但是,我正在使用授權(quán)訪問令牌訪問縮略圖。我可以使用帶有這些訪問令牌的Drive API“Files:get”獲取文件信息,但 thumbnailLink 返回 404。print(http)# <google_auth_httplib2.AuthorizedHttp object at 0x11561d0f0># An instance of google_auth_httplib2.AuthorizedHttpurl = 'https://www.googleapis.com/drive/v3/files/%s?fields=thumbnailLink' % file_idresponse, content = http.request(url)data = json.loads(content)print(data['thumbnailLink'])# https://docs.google.com/u//feeds/vt?gd=true&id=***fileID***&v=203&s=***&sz=s220# Works ?response, content = http.request(data['thumbnailLink'])print(response['status'])# 404# :(還給出了 404 錯(cuò)誤:thumbnailLink + "&access_token=" + YOURTOKEN;如這里所建議的。在瀏覽器中打開thumbnailLink(以文件所有者身份登錄到 Google)。thumbnailLink在瀏覽器中打開修改后的內(nèi)容- 替換/u//為/u/0/, /u/1/, /u/2/(當(dāng)我以該用戶身份打開驅(qū)動(dòng)器時(shí),URL 為https://drive.google.com/drive/u/1/my-drive)有誰知道獲取 Google 云端硬盤縮略圖文件的可靠方法?
查看完整描述

1 回答

?
慕容森

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊

我相信你的目標(biāo)如下。

  • 您想從 Drive API 中的“files.get”方法檢索到的縮略圖鏈接中檢索縮略圖。

  • 從示例縮略圖鏈接中,您想從 Google 文檔(文檔、電子表格等)中檢索縮略圖。

問題和解決方法:

目前階段,從縮略圖看的情況似乎404是bug。這已經(jīng)報(bào)告給了谷歌問題跟蹤器。Ref谷歌方面似乎已經(jīng)為人所知。不幸的是,我認(rèn)為這是當(dāng)前的直接答案。而且,我相信這個(gè)問題會(huì)在未來的更新中得到解決。

在這里,作為當(dāng)前的解決方法,將其轉(zhuǎn)換為 PDF 文件并檢索縮略圖如何?在這種情況下,可以使用縮略圖鏈接。此解決方法的流程如下。

  1. 將 Google 文檔轉(zhuǎn)換為 PDF 文件。

  • PDF 文件創(chuàng)建到與 Google 文檔相同的文件夾中。

從創(chuàng)建的 PDF 文件中檢索縮略圖鏈接。

將上面的流程轉(zhuǎn)換成python腳本后,就變成了下面這樣。

示例腳本:

在使用此腳本之前,請?jiān)O(shè)置訪問令牌和文件 ID。在這種情況下,為了用multipart/form-data簡單的腳本請求,我使用了requests庫。

import json

import httplib2

import requests

import time

http = httplib2.Http()


access_token = '###'? # Please set the access token.

file_id = '###'? # Please set the file ID.


headers = {"Authorization": "Bearer " + access_token}


# 1. Retrieve filename and parent ID.

url1 = "https://www.googleapis.com/drive/v3/files/" + file_id + "?fields=*"

res, res1 = http.request(url1, 'GET', headers=headers)

d = json.loads(res1.decode('utf-8'))


# 2. Retrieve PDF data by converting from the Google Docs.

url2 = "https://www.googleapis.com/drive/v3/files/" + file_id + "/export?mimeType=application%2Fpdf"

res, res2 = http.request(url2, 'GET', headers=headers)


# 3. Upload PDF data as a file to the same folder of Google Docs.

para = {'name': d['name'] + '.pdf', 'parents': d['parents']}

files = {

? ? 'data': ('metadata', json.dumps(para), 'application/json; charset=UTF-8'),

? ? 'file': res2

}

res3 = requests.post(

? ? "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart",

? ? headers=headers,

? ? files=files

)

obj = res3.json()


# It seems that this is required to use by creating the thumbnail link from the uploaded file.

time.sleep(5)


# 4. Retrieve thumbnail link of the uploaded PDF file.

url3 = "https://www.googleapis.com/drive/v3/files/" + obj['id'] + "?fields=thumbnailLink"

res, res4 = http.request(url3, 'GET', headers=headers)

data = json.loads(res4.decode('utf-8'))? # or data = json.loads(res4)

print(data['thumbnailLink'])


# 5. Retrieve thumbnail.

response, content = http.request(data['thumbnailLink'])

print(response['status'])

print(content)

  • 運(yùn)行此腳本時(shí),Google Docs 文件將導(dǎo)出為 PDF 數(shù)據(jù),PDF 數(shù)據(jù)將上傳到 Google Drive 并檢索縮略圖鏈接。

筆記:

  • 在這種情況下,請將范圍包括https://www.googleapis.com/auth/drive到您的訪問令牌的范圍內(nèi)。因?yàn)槲募蟼髁恕?/p>

  • 為了檢索文件元數(shù)據(jù)和導(dǎo)出 PDF 文件并上傳數(shù)據(jù),需要使用訪問令牌。但是當(dāng)從縮略圖鏈接中檢索到縮略圖時(shí),不需要使用訪問令牌。

  • 2020年1月之后,access token不能與查詢參數(shù)一起使用access_token=###,請?jiān)谡埱箢^中使用access token。

  • 解決上述問題后,我認(rèn)為您可以使用您的腳本。


查看完整回答
反對 回復(fù) 2023-05-16
  • 1 回答
  • 0 關(guān)注
  • 302 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號