我正在尝试使用GDrive API v3列出快捷方式文件夹中的所有文件和文件夹。
使用API时,我可以使用以下请求列出所有文件:
curl \
'https://www.googleapis.com/drive/v3/files?q=%27root%27%20in%20parents&supportsAllDrives=true&supportsTeamDrives=true&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
返回如下内容:
{
"kind": "drive#file",
"id": "xxxxxxxxxxxxxx",
"name": "Name of file here",
"mimeType": "application/vnd.google-apps.shortcut"
}
当我获取该ID并将其用于上述相同请求时,该请求适用于"mimeType": "application/vnd.google-apps.folder"
。我得到一个空的有效载荷:
{
"kind": "drive#fileList",
"incompleteSearch": false,
"files": []
}
我使用了错误的端点吗?我还需要向API请求添加其他内容吗?
例如,如果发出请求时,您在云端硬盘中的文件夹只有一个快捷方式,则在根目录中列出所有文件时会得到两个结果。
如果出于某种原因仅获得快捷方式,则可以获取该快捷方式的详细信息:
curl \
'https://www.googleapis.com/drive/v3/files/[YOUR_SHORTCUT_ID]?fields=*&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
(我从响应中删除了大多数字段)
{
"kind": "drive#file",
"id": "[YOUR_SHORTCUT_ID]",
"name": "[YOUR_SHORTCUT_NAME]",
"mimeType": "application/vnd.google-apps.shortcut",
"starred": false,
"trashed": false,
"shortcutDetails": {
"targetId": "[THE_ACTUAL_FOLDER_ID]",
"targetMimeType": "application/vnd.google-apps.folder"
}
}
里面shortcutDetails
是targetId
。
之后,您可以使用编写原始请求"ID" in parents
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句