Google Drive files not specified in driver

I am trying to get a list of files in my Google Drive using a desktop application. The code is as follows:

def main(argv):

    storage = Storage('drive.dat')
    credentials = storage.get()

    if credentials is None or credentials.invalid:
        credentials = run(FLOW, storage)

    # Create an httplib2.Http object to handle our HTTP requests and authorize it
    # with our good Credentials.
    http = httplib2.Http()
    http = credentials.authorize(http)

    service = build("drive", "v2", http=http)
    retrieve_all_files(service)

Then, in the retrieve_all_files file, I print the files:

param = {}
if page_token:
    param['pageToken'] = page_token
    files = service.files().list(**param).execute()
    print files

But after I authenticate my account, the list of print files has no items. Does anyone have a similar problem or is aware of a solution to this?

+5
source share
2 answers

Please correct me if I am mistaken, but I believe that you are using an area https://www.googleapis.com/auth/drive.filethat returns files created or opened by your application using the Google Drive UI or Picker API.

, : https://www.googleapis.com/auth/drive.

, .

+7

-, page_token, My Drive, . , .. :

def retrieve_all_files(service):
    """ RETURNS a list of files, where each file is a dictionary containing
        keys: [name, id, parents]
    """

    query = "trashed=false"

    page_token = None
    L = []

    while True:
        response = service.files().list(q=query,
                                             spaces='drive',
                                             fields='nextPageToken, files(id, name, parents)',
                                             pageToken=page_token).execute()
        for file in response.get('files', []):  # The second argument is the default
            L.append({"name":file.get('name'), "id":file.get('id'), "parents":file.get('parents')})

        page_token = response.get('nextPageToken', None)  # The second argument is the default

        if page_token is None:  # The base My Drive folder has None
            break

    return L
0

All Articles