pydrive:知道 id 后如何重命名 google 电子表格的标题?

pydrive: how do I rename the title of a google spreadsheet once I know the id?

Here 下 "Update file metadata" 它展示了如何更改已创建文件的标题。如果我知道 id 或密钥,我正在寻找如何更改标题。或者在 gspread?

中有什么方法可以做到吗?

我找到了

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)

id='xxxxxxxxxxxxxxxxxxxxxxxx'
a=drive.auth.service.files().get(fileId=id).execute()
a['title']="new title"
update=drive.auth.service.files().update(fileId=id,body=a).execute()

您也可以直接使用 PyDrive 执行此操作。 CreateFile() 仅创建一个本地 Python 对象来表示新文件或现有文件的状态

# CreateFile() can be called with an existing id.
file1 = drive.CreateFile({'id': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'})

file1['title'] = '<new title>' # Change title.
file1.Upload()                 # Upload new title.