I am facing the following issue while getting files/folders for OneDrive of a user.
On hitting
https://graph.microsoft.com/v1.0/users/{user-id}/drive
I get this in the response:
"quota": {
"deleted": 0,
"remaining": 0,
"total": 0,
"used": 0
}
which denotes that the drive isn't being used or is empty.
On hitting
https://graph.microsoft.com/v1.0/users/{user-id}/drive/root
I get the response -
"folder": {
"childCount": 21
},
"root": {},
"size": 281236319
Here, it denotes that there are 21 files/folders in the drive's root folder and they occupy 281.23 MB of space.
Now, on hitting https://graph.microsoft.com/v1.0/users/{user-id}/drive/root/children
I get empty vector in the response -
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('user-id')/drive/root/children",
"value": []
}
There are files present in the drive. But I am not able to get them via the children API. Any help in understanding these 3 different results and getting the response would be appreciated
Thanks.
Once your user is authenticated and you retrieve an Access Token on behalf of that user. You would simply call this endpoint:
https://graph.microsoft.com/v1.0/me/drive/root/children
You may also want to look into a folder on that users OneDrive as well:
https://graph.microsoft.com/v1.0/me/drive/root:{/Folder-Path}:/children
Your URL is correct as well and should work as I just tested using my 'user-id' and was able to retrieve the files in my onedrive.
https://graph.microsoft.com/v1.0/users/{user-id}/drive/root/children
References:
https://stackoverflow.com/a/46614072/6559330 https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_list_children
This issue is caused by calling the using the incorrect URL. The docs don't make it very clear but the URL:
https://graph.microsoft.com/v1.0/me/drive
Does not work if the 'Drive' is actually part of a share point instance. Although the UI says "Drive" when logged in as the user, the URL contains reference to being share point.
The correct url to use is actually:
https://{tenant}-my.sharepoint.com/_api/v2.0/drives/{drive id}/root/
You must use the scope Files.Read.All
or Files.ReadWrite.All
. In doing so, your requests to will no longer return an empty array.
来源:https://stackoverflow.com/questions/46687268/list-children-api-doesnt-give-all-the-children-of-the-drive-folder