Python 3.x 用Python实现googledrive查询

Python 3.x 用Python实现googledrive查询,python-3.x,google-drive-api,Python 3.x,Google Drive Api,我想查询(使用Python)google drive中特定文件夹中的文件列表。我使用了以下代码。它返回所有文件夹的所有文件的文件列表,但我无法获取特定文件夹的列表。有人能帮忙吗?谢谢 from __future__ import print_function import time from apiclient import discovery from httplib2 import Http from oauth2client import file, client, tools SCOP

我想查询(使用Python)google drive中特定文件夹中的文件列表。我使用了以下代码。它返回所有文件夹的所有文件的文件列表,但我无法获取特定文件夹的列表。有人能帮忙吗?谢谢

from __future__ import print_function
import time
from apiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools

SCOPES = 'https://www.googleapis.com/auth/drive.readonly.metadata'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)

DRIVE = discovery.build('drive', 'v3', http=creds.authorize(Http()))
file_service = DRIVE.files()
files = file_service.list().execute().get('files', [])
for f in files:
file_shared = (file_service.get(fileId=f['id'], fields="name, 
shared").execute())

# Only display files that are shared
if file_shared['shared']:
    print(file_shared['name'], f['id'])
    #for f in file_shared:
    #   print('title: %s, id: %s' % (f['title'], f['id']))

# Sleep 1/10 of a second between every API call, otherwise
# you will exceed the number of calls allowed
time.sleep(.100)

这次修改怎么样

修改点:
  • 要检索特定文件夹中的文件列表,请使用
    q
    for
    file\u service.list()
修改脚本: 请修改如下

发件人: 致:
  • ####folderId####
    是文件夹ID
参考:

虽然我不确定这是否是您问题的直接解决方案,但当您想要检索特定文件夹中的文件列表时,如何从
files=file_-service.list().execute().get('files',[])
修改为
files=file_-service.list(q=“”########在parents中”).execute().get('files',[])
?查询的文档是哇!它像魔术一样工作!非常感谢塔奈克!!尝试投票/接受您的解决方案..未找到..感谢您的回复。我很高兴你的问题解决了。谢谢你的关心。我把它贴了。你能确认一下吗?
files = file_service.list().execute().get('files', [])
files = file_service.list(q="'### folderId ###' in parents").execute().get('files', [])