2016-10-29 11 views
0

此功能:無效查詢,驅動器API,files.list()

drive.ListFile({'q': " id = '"+Value+"' and trashed=false"}).GetList() 

回報: 「無效查詢」

問題在於選擇 '身份證',如果我提出這個條件我返回一個字典,我用這個文檔的參數 'ID'

https://developers.google.com/drive/v2/reference/files/listhttps://developers.google.com/drive/v3/web/search-parameters

它完全適用於其他的選擇,但對於「ID」不應該是

+0

是否有您想要我們回答的問題?還是一個目標? – Ukimiku

+0

我需要運行功能 – simone989

+0

你是什麼意思,「[...]但'ID'它不應該是」?它不應該是什麼? –

回答

2

編輯:這裏是你如何訪問元數據,並獲得通過它的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的例子。

確保您

  1. 不要引入周邊=跡象,
  2. PyDrive使用谷歌雲端硬盤API V2你自己的空間,所以一定要使用the v2 search parameter page代替,
  3. 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'])) 
1

id不是做搜索文件支持的查詢字段。

檢查文檔for Drive API v2以查看要搜索的有效字段。