I’m trying to get a list of all the files and documents a user can see in their Google Drive. I thought I could use the Google Document List API, but it’s not working out.
But I keep getting an ‘Invalid request URI’ error. I’m pretty sure I’m missing something obvious, but I can’t figure out what. Does anyone know what I’m doing wrong or if there’s a better way to do this? I just need to get the IDs of all the documents the user can access. Thanks for any help!
I’d like to add that while the Google Drive API v3 is indeed the correct approach, it’s important to consider the scope of your request when setting up authentication. Make sure you’re using the ‘https://www.googleapis.com/auth/drive.readonly’ scope to access all files and folders the user can see.
Also, depending on your use case, you might want to filter the results. The ‘files().list()’ method accepts a ‘q’ parameter for query filtering. For example, to get only Google Docs:
This can significantly reduce API usage and processing time if you don’t need all file types. Remember to handle potential API errors and implement exponential backoff for retries to ensure robust operation.
hey joec, i think ur using an outdated API. try the google drive API v3 instead. u can use the files.list method to get all the files n folders. heres a quick example:
from googleapiclient.discovery import build
service = build('drive', 'v3', credentials=creds)
results = service.files().list().execute()
I’ve been in a similar situation, and I found that using the Google Drive API v3 is indeed the way to go. However, to get all document IDs a user can access, you’ll need to handle pagination and potentially deal with a large number of results.
Here’s what worked for me:
from googleapiclient.discovery import build
service = build('drive', 'v3', credentials=creds)
page_token = None
all_files = []
while True:
response = service.files().list(pageSize=1000,
fields='nextPageToken, files(id, name)',
pageToken=page_token).execute()
all_files.extend(response.get('files', []))
page_token = response.get('nextPageToken')
if not page_token:
break
file_ids = [file['id'] for file in all_files]
This approach ensures you get all files, even if there are thousands. Just be mindful of API quotas and rate limits if you’re dealing with a very large Drive.