You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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:
This returns:
Now, I’m trying to get all file IDs in that folder:
But this returns:
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:
The text was updated successfully, but these errors were encountered: