【发布时间】:2020-11-04 17:08:24
【问题描述】:
我正在尝试使用 Drive Python API 公开一些幻灯片和电子表格。首先我上传文件,然后我得到 id 来应用修订更新并且没有发生错误,但没有应用更改。我也使用了API explorer,但同样的情况发生了。我也使用了分配的 revisionId 而不是“head”,没有区别。对可能发生的事情有任何想法吗?
我的代码:
from Google import Create_Service
from googleapiclient.http import MediaFileUpload
CLIENT_SECRET_FILE = 'credentials.json'
API_NAME = 'drive'
API_VERSION = 'v3'
SCOPES = ['https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.appdata', 'https://www.googleapis.com/auth/drive.file']
service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
folder_id = 's0m3Id$tr1n9'
file_name = 'excel.xlsx'
file_mime_type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
file_metadata = {
'name': file_name,
'parents': [folder_id]
}
# Uploaing file
media = MediaFileUpload(f'./uploads/{file_name}', mimetype=file_mime_type)
file_id = service.files().create(
body = file_metadata,
media_body = media,
fields = 'id'
).execute()['id']
print(f'Assigned ID: {file_id}')
# Revision
public_slide = service.revisions().update(
fileId = file_id,
revisionId = 'head',
body = {
'published': True,
'publishAuto': True
}
).execute()
print(public_slide)
【问题讨论】:
-
你到底做了哪些改变?
-
@DaImTo 上传文件后,我更新了头部修订,将
published字段更改为True,以便公开文档,类似于“发布到网络”下的Google 表格/演示文稿的文件菜单
标签: python google-drive-api client google-api-python-client