Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Drive API not listing files in folder despite files existing #2502

Open
dineshsonachalam opened this issue Oct 17, 2024 · 0 comments
Open
Assignees

Comments

@dineshsonachalam
Copy link

I’m trying to list all the file IDs in a specific folder in Google Drive using the Drive API.

First, I find the folder ID like this:

import requests

headers = {
    "Authorization": GCP_ACCESS_TOKEN,
    "Content-Type": "application/json"
}

# Find a folder's ID
parent_folder_id = "12345"
folder_name = "photos"
query = f"name='{folder_name}' and '{parent_folder_id}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"
params = {
    "q": query,
    "fields": 'files(id)'
}

response = requests.get("https://www.googleapis.com/drive/v3/files", headers=headers, params=params)
print(response.json())

This returns:

{'files': [{'id': "6789"}]}

Now, I’m trying to get all file IDs in that folder:

folder_id = "6789"
query = f"'{parent_folder_id}' in parents and mimeType='application/vnd.google-apps.file' and trashed=false"
params = {
    "q": query,
    "fields": 'files(id)'
}

response = requests.get("https://www.googleapis.com/drive/v3/files", headers=headers, params=params)
print(response.json())

But this returns:

{"files": []}

It’s weird because this folder has two files. I’m not sure what’s happening.

What am I doing wrong? How can I correctly list all the file IDs in a folder?

Additional Information:

•	I’m using Python and the requests library.
•	The folder definitely contains two files.
•	The authorization token is valid and working, as I can retrieve other data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants