[英]Certain files missing in Google Drive API v3 Python files().list()
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. 我是使用适用于Python(v3)的Google Drive API的新手,并且一直在尝试访问和更新我具有fileId的特定父文件夹中的子文件夹。 Here is my build for the API driver:
这是我为API驱动程序构建的:
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: 我可以通过使用
files().list()
成功访问大多数子文件夹,但返回的结果列表中至少缺少一个子文件夹:
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. 我仔细检查了一下,结果中没有
nextPageToken
键, incompleteSearch
的值为False
,我认为这意味着将返回完整的结果列表。 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: 另外,当我使用
file().get()
方法访问丢失文件的父级列表时,列出的唯一父级是上面查询中的父级:
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: 其他可能相关的细节:
UPDATES 更新
files().list()
query used to return 40 records of the 41 in the folder. files().list()
查询用于返回文件夹中41条记录的40条记录。 Now it is only returning 39. files().get()
both of the non-returned folders still have the parent folder as their only parent, and their permissions have not changed. files().get()
查询其文件夹详细信息时,两个未返回的文件夹仍将其父文件夹作为其唯一的父文件夹,并且它们的权限没有更改。 Main questions: 主要问题:
file().list()
query showing up in the results of that query? file().list()
查询中显然没有列出父ID的file().list()
显示在该查询的结果中? And is there any way to adjust the query or the file to ensure that it does? children()
method for folders, but it's been deprecated in v3 to my knowledge children()
方法,但据我所知在v3中已弃用 I figured out the error with my code: 我用我的代码找出了错误:
My previous query parameter in the files().list()
method was: 我在
files().list()
方法中的上一个查询参数是:
results = service.files().list(
q="parents in '1QXPl6z04GsYAO0GKHBk2oBjEweaAbczw'",
fields="files(id, name), incompleteSearch, nextPageToken").execute()
items = results['files']
After looking at another bug someone had posted in Google's issue tracker for the API, I saw the preferred syntax for that query was: 在查看了有人在Google的问题跟踪器中针对该API发布的另一个错误之后,我看到了该查询的首选语法是:
results = service.files().list(
q="'1QXPl6z04GsYAO0GKHBk2oBjEweaAbczw' in parents",
fields="files(id, name), incompleteSearch, nextPageToken").execute()
items = results['files']
In other words switching the order of parents in fileId
to fileId in parents
. 换句话说
parents in fileId
将fileId in parents
顺序切换为parents in fileId
中的fileId in parents
。 With the resulting change in syntax all 41 files were returned. 随着语法的更改,返回了所有41个文件。
I have two follow-up questions that hopefully someone can clarify: 我有两个后续问题,希望有人可以澄清:
parents in ...
syntax would suggest? parents in ...
语法中的parents in ...
所建议的那样? Or do they have to be evaluated as separate conditions ie fileId1 in parents or fileId2 in parents
? fileId1 in parents or fileId2 in parents
? If someone could comment on this answer with those explanations or post a more complete answer, I would gladly select it as the best response. 如果有人可以用这些解释对这个答案发表评论或发布更完整的答案,我很乐意将其选择为最佳答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.