I have a corporate account and I asked to set up Application Permission with the scope Files.ReadWrite.All to be able to access msgraph Python SDK in order to use Drive/DriveItem APIs under the "Files" documentation of msgraph.
I am not able to understand how to use the SDK though. After creating a client with my credential, I tried different requests without success, meaning that I am not able to see what I expect.
So I wish to ask, if I have the following URL:
https://mycompany-my.sharepoint.com/my?id=%2Fpersonal%2my_user_id%2FDocuments%2FDocuments
Which is a folder named "Documents" under "My Files" in my Onedrive for Business dashboard (which seems like a sharepoint library). How can I query it?
I tried, for instance, examples like this:
self.client.users.by_user_id(user_id).drives.by_drive_id(drive_id).items
self.client.users.by_user_id(user_id).drives.by_drive_id(drive_id).root.children.get()
My problem, is that after I get my desired Drive object (I believe), I am not able to access the items/root attributes because either they don't exist (so I am making a bad requests) or they exist but are None values.
I am able to list 2 drives, one named "OneDrive" which is the one I use as ID, and the other one is a PersonalCache.
To access root item, you can call by_drive_item_id('root')
.
If you know drive id, you can omit users.by_user_id(user_id)
childItems = await self.client.drives.by_drive_id(drive_id)
.items.by_drive_item_id('root').children.get()
It will return only 200 items from the first page.
Example how to implement paging can be found in SDK repo:
https://github.com/microsoftgraph/msgraph-sdk-python?tab=readme-ov-file#32-pagination