Get file size from Google Drive Api (python)

Per default, only a few select attributes are included in the metadata.

To request specific attributes, use the fields parameter:

file = self.drive_service.files().get(fileId=file_id, fields='size,modifiedTime').execute()

This would query a file's size and modification time.

By the way, the link you posted refers to the old v2 API. You can find a list of all file attributes in the current v3 API here.


You are missing the 'fields' special query parameter here. It is used for giving partial response for google apis. The partial response is used mainly to improve api call performance.

There is a slight change in the newly introduced v3 apis, the file list apis response give some default attributes in the response, unlike the v2 apis, which give all the attributes in response by default.

Although, if you want all the attributes in the response, pass ' fields=* ' as query.

Hope, this helps!