sat_yug
sat_yug

Reputation: 203

How to get the files list from the folder using files:list in the google drive

I don't have prior experience on google drive. I need to get the list of files present in the folder of google drive and get the details of the files.

Example:

Drive  
     |--Folder  
             |-File1
             |-File2
     |--File3
     |--File4

I need the details of all the files say File 1,2,3,4. I am able to get the details of File3 and File4 with the below code:

def main():
    """Shows basic usage of the Google Drive API.

    Creates a Google Drive API service object and outputs the names and IDs
    for up to 10 files.
    """
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    param['q']="'root' in parents"
    service = discovery.build('drive', 'v2', http=http)
    results = service.files().list(**param).execute()
    page_token = None
    items = results.get('items', [])
    if not items:
        print('No files found.')
    else:
        print('Files:')
        for item in items:
            keys = list(item.keys())
            print('{0} ,{1} ,{2}, {3}, {4}, {5}, {6}'.format(item['title'],
                                                    item['createdDate'],
                                                    item['lastModifyingUserName'],
                                                    item['modifiedByMeDate'],
                                                    item['modifiedDate'],
                                                    item['ownerNames'],
                                                    item['mimeType']))

From the quickstart guide of google api.

May I know how can I get the details of File1, File2 present in Folder as shown above?

Upvotes: 2

Views: 1067

Answers (2)

pinoyyid
pinoyyid

Reputation: 22296

You simply need to remove the line

param['q']="'root' in parents"

and then you'll get all files. When I say "all" files, that includes deleted files. To get only undeleted files, you would add the line

param['q']="trashed = false"

Upvotes: 1

abielita
abielita

Reputation: 13469

You should use files.list with a parent query. Example:

GET https://www.googleapis.com/drive/v2/files?q='BB0CHANGEDIDF5waGdzbUQ5aWs'+in+parents&key={YOUR_API_KEY}

You can search or filter files with the files.list method that accepts the q parameter which is a search query combining one or more search clauses. Each search clause is made up of three parts.

You can also check this tutorial and related SO question.

Upvotes: 1

Related Questions