Google Drives API - retrieve files owned by me

Viewed 556

Using the Google Drives API, how do I formulate Q when retrieving the file listing, to only get back files that are owned by me?

1 Answers

I believe your goal as follows.

  • You want to retrieve the files that you are the owner using the method of "Files: list" in Drive API.
  • You want to create the search query for achieving this.

For this, how about this answer?

In this case, you can create the search query using owners in the fields.

Sample search query:

'me' in owners

If you want to retrieve the files in the specific folder, you can use the following search query.

'###' in parents and 'me' in owners

Sample curl:

curl \
  'https://www.googleapis.com/drive/v3/files?q=%27me%27%20in%20owners&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed

and

curl \
  'https://www.googleapis.com/drive/v3/files?q=%27%23%23%23%27%20in%20parents%20and%20%27me%27%20in%20owners&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed

Note:

  • If you want to retrieve the folder without publicly sharing, please use the access token instead of the API key. Please be careful this.

References:

Related