Search code examples
google-apigoogle-drive-apigoogle-api-clientgoogle-api-python-client

Google Drive API: the get() method on drive_service.files().list() documented?


In this link there a get method in Python:

response = drive_service.files().list(q="mimeType='image/jpeg'",
                                          spaces='drive',
                                          fields='nextPageToken, files(id, name)',
                                          pageToken=page_token).execute()
    for file in response.get('files', []):

I guess the get() method will get a list of files, and if none, it will return an empty list, but where is this documented? The API doc does not have it. It simply says:

Returns:
  An object of the form:
...

It did not document any method.


Solution

  • From your script, I thought that get of for file in response.get('files', []): is the method of the built-in type. Ref

    From your fields of fields='nextPageToken, files(id, name)', drive_service.files().list() returns an object like {"nextPageToken": "###", "files": [{"id": "###", "name": "###"},,,]}. Ref When files of mimeType='image/jpeg' isn't found, {"files": []} is returned.

    In this case, you can also use response.get('files').

    References: