在 MS Graph 中获取其他 Onedrive 中的所有文件

Get all the files in others Onedrive in MS Graph

我正在尝试列出另一个用户的 OneDrive 中的所有文件。

我正在呼叫 GET /users/{user-id}/drive/items/{item-id}/children,但我的问题是我不知道如何获得 {item-id}

我尝试使用 https://graph.microsoft.com/v1.0/users/{userid}/drives 但它没有显示任何项目 ID。

后续,一旦我得到id,我将使用复制命令POST /users/{userId}/drive/items/{itemId}/copy来复制项目。

您可能需要查询 root 以获得 files/folders

的 childID
GET https://graph.microsoft.com/v1.0/users/{user-id}/drive/root/children

如果您不知道 DriveItem 的 ID 或路径,您需要从 Drive 的根目录开始,遍历文件夹结构,直到找到文件) 您正在寻找。

您的第一个电话是 /users/{id|userPrincipalName}/drive/root/children?$select=id,name,folder,file。这将 list the children's idname 以及 folderfile 数据(取决于项目类型)来自 root 文件夹:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('id')/drive/root/children(id,name,folder,file)",
    "value": [
        {
            "@odata.etag": "\"{etag},1\"",
            "id": "folderId",
            "name": "My Folder",
            "folder": {
                "childCount": 10
            }
        },
        {
            "@odata.etag": "\"{etag},1\"",
            "id": "fileId",
            "name": "filename.ext",
            "file": {
                "mimeType": "type",
                "hashes": {
                    "quickXorHash": "hash"
                }
            }
        }
    ]
}

然后您对每个文件夹执行相同的调用以获取它们的子文件夹,重复该模式直到找到您要查找的文件:

/users/{id|userPrincipalName}/drive/items/{folderId}/children?$select=id,name,folder,file`

或者,您可以简单地 search for the file 使用 /users/{id|userPrincipalName}/drive/root/search(q='{search-text}')