一个驱动器。 MS 图 API。将文件移动到驱动器根目录失败 "One of the provided arguments is not acceptable"

OneDrive. MS Graph API. Move file to root of drive fails with "One of the provided arguments is not acceptable"

我有使用 MS graph API for onedrive 的应用程序。 当我尝试将文件从某个文件夹移动到驱动器的根目录时出现错误 "One of the provided arguments is not acceptable".

但相同的代码适用于 "individual" onedrive 帐户,问题仅适用于 OneDrive for business 帐户。 另外,移动到任何其他文件夹都可以正常工作。

我正在发送 PATCH 请求或移动文件。

对于免费的 onedrive,请求正文如下所示

(
    [parentReference] => 
        (
            [path] => //drives/68XXXXX7f7f7d7c/root
        )
)

这行得通。但 oneDrive for business 的相同代码失败了

(
    [parentReference] => 
        (
            [path] => //drives/b!-0dIs3JX..TRUNCATED...0_oR2A...L0PY/root
        )
)

这给出了错误 "One of the provided arguments is not acceptable"

这是什么?有任何想法吗? 我按照这里的文档 https://docs.microsoft.com/en-us/graph/api/driveitem-move?view=graph-rest-1.0

此问题已在 documentation 中注明:

Note: When moving items to the root of a drive your app cannot use the "id:" "root" syntax. Your app needs to provide the actual ID of the root folder for the parent reference.

要检索实际 ID,您需要从 root 对象中检索 id

/drives/{drive-id}/root

这将 return 类似于以下内容:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('48d31887-5fad-4d73-a9f5-3c356e68a038')/drive/root/$entity",
    "createdDateTime": "2017-07-27T02:41:36Z",
    "id": "01BYE5RZ56Y2GOVW7725BZO354PWSELRRZ",
    "lastModifiedDateTime": "2019-01-18T03:41:15Z",
    "name": "root",
    "webUrl": "https://m365x214355-my.sharepoint.com/personal/meganb_m365x214355_onmicrosoft_com/Documents",
    "size": 106330475,
    "parentReference": {
        "driveId": "b!-RIj2DuyvEyV1T4NlOaMHk8XkS_I8MdFlUCq1BlcjgmhRfAj3-Z8RY2VpuvV_tpd",
        "driveType": "business"
    },
    "fileSystemInfo": {
        "createdDateTime": "2017-07-27T02:41:36Z",
        "lastModifiedDateTime": "2019-01-18T03:41:15Z"
    },
    "folder": {
        "childCount": 38
    },
    "root": {}
}

使用上面的例子,当移动文件时,你的路径是:

/drives/b!-RIj2DuyvEyV1T4NlOaMHk8XkS_I8MdFlUCq1BlcjgmhRfAj3-Z8RY2VpuvV_tpd/01BYE5RZ56Y2GOVW7725BZO354PWSELRRZ