使用Python&;获取Google Drive中文件夹的内容;APICLient

使用Python&;获取Google Drive中文件夹的内容;APICLient,python,google-drive-api,Python,Google Drive Api,我正在尝试使用Python中的apiclient模块获取Google驱动器文件夹的内容 这是我的密码 #!/usr/bin/env python from __future__ import print_function import os from apiclient.discovery import build from httplib2 import Http from oauth2client import file, client,

我正在尝试使用Python中的apiclient模块获取Google驱动器文件夹的内容

这是我的密码

    #!/usr/bin/env python

    from __future__ import print_function
    import os

    from apiclient.discovery import build
    from httplib2 import Http
    from oauth2client import file, client, tools
    import requests
    try:
        import argparse
        flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
    except ImportError:
        flags = None

    SCOPES = 'https://www.googleapis.com/auth/drive.file'
    store = file.Storage('storage.json')
    creds = store.get()
    if not creds or creds.invalid:
        flow = client.flow_from_clientsecrets('client_secrets.json', SCOPES)
        creds = tools.run_flow(flow, store, flags) \
                if flags else tools.run(flow, store)
    DRIVE = build('drive', 'v2', http=creds.authorize(Http()))
    print (DRIVE.children().list( folderId='# id of the folder').execute()['items'])
然而,我得到的只是一个空列表,而不是一个填充的列表。我知道文件夹里有文件

我在这里引用代码。


建议

我猜您没有在您的
if语句中包含
creds=tools.run\u flow(flow,store,flags)

if not creds or creds.invalid:
        flow = client.flow_from_clientsecrets('client_secrets.json', SCOPES)
        creds = tools.run_flow(flow, store, flags) \
                if flags else tools.run(flow, store)
这应该是:

if not creds or creds.invalid:
        flow = client.flow_from_clientsecrets('client_secrets.json', SCOPES)

        if flags:
            creds = tools.run_flow(flow, store, flags)
        else:
            creds = tools.run(flow, store)
你可以在这里找到它