I'm new to using the Google Drive API for Python (v3) and I've been trying to access and update the sub-folders in a particular parent folder for which I have the fileId. Here is my build for the API driver:
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json',
scope='https://www.googleapis.com/auth/drive')
creds = tools.run_flow(flow, store)
service = build('drive', 'v3', http=creds.authorize(Http()))
I am able to successfully access most of the sub-folders by using files().list()
but at least one was missing from the list of results returned:
results = service.files().list(
q="parents in '1QXPl6z04GsYAO0GKHBk2oBjEweaAbczw'",
fields="files(id, name), incompleteSearch, nextPageToken").execute()
items = results['files']
I double checked and there was no nextPageToken
key in the results and the value of incompleteSearch
was False
, which I assume means the full list of results were returned. In addition when I accessed the list of parents for the missing file by using the file().get()
method, the only parent listed is the one in the query above:
service.files().get(
fileId='1WHP02DtXfJHfkdr47xSeeRIj0sCrihPA',
fields='parents, name').execute()
and returns this:
{'name': 'Sara Gaul -Baltimore Corps docs and schedules',
'parents': ['1QXPl6z04GsYAO0GKHBk2oBjEweaAbczw']}
Other details that may be relevant:
- This particular folder that is not appearing in the list was renamed by a collaborator.
- I'm running this code on a jupyter notebook instead from a python file.
- I'm a named collaborator with write access on all of the sub-folders, including the one that's not showing up.
UPDATES
- The
files().list()
query used to return 40 records of the 41 in the folder. Now it is only returning 39. - Both of the folders that are no longer being returned were renamed by someone who accessed the folder using the link that extends write level permissions.
- When their folder details are queried directly using
files().get()
both of the non-returned folders still have the parent folder as their only parent, and their permissions have not changed.
Main questions:
- Why isn't this file which clearly has the parent id listed in my
file().list()
query showing up in the results of that query? And is there any way to adjust the query or the file to ensure that it does? - Is there an easier way to list all of the files contained within a folder in the Google Drive API v3? I know that v2 had a
children()
method for folders, but it's been deprecated in v3 to my knowledge