N
N
newPsevdonim2021-08-15 17:23:35
Python
newPsevdonim, 2021-08-15 17:23:35

How to get a list of Google drive directory file IDs?

I am trying to download files from a specific google drive folder. I couldn’t download the folder directly, but I got an error that only binary files can be downloaded this way. Then I tried to get the id of the files of a specific folder and download them in a loop. Here is the code I tried to use to get the id of the folder files:

def make_conect():
    CLIEN_SECRET_FILE = 'client_secret_844464197570-vh4is72q90s1qmoc2pbgmk8r9vlhv61m.apps.googleusercontent.com.json'
    API_NAME = 'drive'
    API_VERSION = 'v3'
    SCOPES = ['https://www.googleapis.com/auth/drive']
    service = Create_Service(CLIEN_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
    return service
service = make_conect()


file_list = service.ListFile(
{'q': "'1R6eT6NE19_9LshSK3FsIHMVY6KOkhrG2' in parents"}).GetList()


The error I am getting is:

Traceback (most recent call last):
File "D:\pythonProject1\google.py", line 148, in <module>
file_list = service.ListFile(
AttributeError: 'Resource' object has no attribute 'ListFile'


how can i fix this or upload files from specific folder?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2021-08-15
@newPsevdonim

True for Google Drive API v3 and original client library

#!/usr/bin/python
# -*- coding: utf-8 -*-
page_token = None
while True:
    response = \
        drive_service.files().list(q="'1R6eT6NE19_9LshSK3FsIHMVY6KOkhrG2' in parents"
                                   , spaces='drive',
                                   fields='nextPageToken, files(id, name)'
                                   , pageToken=page_token).execute()
    for file in response.get('files', []):

        # Process change

        print 'Found file: %s (%s)' % (file.get('name'), file.get('id'))
    page_token = response.get('nextPageToken', None)
    if page_token is None:
        break

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question