編輯:這裏是你如何訪問元數據,並獲得通過它的ID設置現有文件的內容。
# Calling CreateFile() with an existing ID links it to the already existing file.
gdrive_file = drive.CreateFile({'id': '<your file id>'})
gdrive_file.FetchMetadata() # Only needed if you want to view or edit its metadata.
# Do things with metadata here as needed.
gdrive_file.GetContentFile('dog.png') # Download content file.
# And/or upload a new content file.
gdrive_file.SetContentFile('cat.png')
gdrive_file.Upload()
而且,當然,docs有一堆例子。
原始: 查看docs for file listings的例子。
確保您
- 不要引入周邊
=
跡象,
- PyDrive使用谷歌雲端硬盤API V2你自己的空間,所以一定要使用the v2 search parameter page代替,
- ID是Google Drive分配的文件夾ID爲this SO question列出了查找ID的方式。
例如:
from pydrive.drive import GoogleDrive
drive = GoogleDrive(gauth) # Create GoogleDrive instance with authenticated GoogleAuth instance
folder_id = "insert your folder ID here"
# Auto-iterate through all files in the specified folder.
file_list = drive.ListFile({
'q': "{id} in parents and trashed=false".format(id=folder_id)
}).GetList()
for file1 in file_list:
print('title: %s, id: %s' % (file1['title'], file1['id']))
是否有您想要我們回答的問題?還是一個目標? – Ukimiku
我需要運行功能 – simone989
你是什麼意思,「[...]但'ID'它不應該是」?它不應該是什麼? –