在为用户的OneDrive获取文件/文件夹时,我面临以下问题。
在打
https://graph.microsoft.com/v1.0/users/ {用户ID} /驱动
我在回复中得到了这个:
"quota": {
"deleted": 0,
"remaining": 0,
"total": 0,
"used": 0
}
表示驱动器未被使用或为空。
在击中https://graph.microsoft.com/v1.0/users/{user-id}/drive/root
我得到了回应 -
"folder": {
"childCount": 21
},
"root": {},
"size": 281236319
这里,它表示驱动器的根文件夹中有21个文件/文件夹,它们占用281.23 MB的空间。
现在,在击中https://graph.microsoft.com/v1.0/users/{user-id}/drive/root/children
时,我在响应中得到空矢量 -
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('user-id')/drive/root/children",
"value": []
}
驱动器中存在文件。但我无法通过子API获取它们。任何帮助理解这3个不同的结果并获得响应将不胜感激
谢谢。
一旦您的用户通过身份验证,您就代表该用户检索访问令牌。您只需调用此端点:
https://graph.microsoft.com/v1.0/me/drive/root/children
您可能还想查看该用户OneDrive上的文件夹:
https://graph.microsoft.com/v1.0/me/drive/root:{/Folder-Path}:/children
您的网址也是正确的,应该像我刚刚使用我的'user-id'测试一样,并且能够检索我的onedrive中的文件。
https://graph.microsoft.com/v1.0/users/{user-id}/drive/root/children
参考文献:
https://stackoverflow.com/a/46614072/6559330 https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_list_children
此问题是由调用使用不正确的URL引起的。文档没有说清楚,但URL:
https://graph.microsoft.com/v1.0/me/drive
如果'Drive'实际上是共享点实例的一部分,则不起作用。虽然UI以用户身份登录时显示“Drive”,但URL包含对共享点的引用。
正确使用的URL实际上是:
https:// {tenant} -my.sharepoint.com/_api/v2.0/drives/ {drive id} / root /
您必须使用范围Files.Read.All
或Files.ReadWrite.All
。这样做,您的请求将不再返回空数组。