我正在尝试下载一些 google doc 文件,但之后我需要使用导出方法转换为 microsoft word mimetype,它工作正常,直到找到一个大小超过 10 mb 的文件,api 文档说这是限制导出文档的大小,但我确实需要下载这些文件,我的脚本中的所有内容都工作正常,除了抛出的错误是
“此文件太大,无法导出。”。详细信息:“此文件太大,无法导出。”
那么,是否有办法避免此限制或导出内容文件夹内的文档
EDIT:我尝试下载的文档不是公开的,因此我认为我需要对请求进行身份验证才能获取内容
EDIT 2: 脚本:
SCOPES = ['https://www.googleapis.com/auth/drive.file','https://www.googleapis.com/auth/drive','https://www.googleapis.com/auth/spreadsheets']
def main():
#----------------------Google drive auth-----------------------------
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
# Call the Drive v3 API
service = build('drive', 'v3', credentials=creds)
sheets_service = build('sheets', 'v4', credentials=creds)
# Call the Sheets API
sheet = sheets_service.spreadsheets()
# ID of folder that contain the wanted files
query = "'[ID OF THE FOLDER]' in parents"
response = service.files().list(q=query,
spaces='drive',
fields='files(id, name, parents, webViewLink,exportLinks)').execute()
baseURL="https://docs.google.com/document/d/"
for document in response['files']:
downloadURL=baseURL+document["id"]+"/export?format=doc"
r = requests.get(downloadURL)
with open('pathtosabe, 'wb') as f:
f.write(r.content)
main()