How to access a document library in a sharepoint online site using MS graph

喜夏-厌秋 提交于 2019-12-21 20:47:43

问题


I am able to access the documents on my one drive with requests like this one:

https://graph.microsoft.com/v1.0/me/drive/root/children

I am able to access a document library of a root sharepoint site of my company with a request like this:

https://graph.microsoft.com/v1.0/drive/root/children

It gives me the contents of the "root" library:

https://<my company>.sharepoint.com/Shared%20Documents

I am not able to access the document library of a SP subsite I created. e.g. this one:

https://<my company>.sharepoint.com/samplesp/Shared%20Documents

How can I access such a document library with MS Graph?


回答1:


For accessing SharePoint sites and lists check out documentation of the SharePoint API in Microsoft Graph.

Update:

For those who have problems with accessing default Drive (formerly "Documents" library) on a specific SharePoint site using MS Graph API:

You should look into the documentation for accessing files on OneDrive.

As said in the question, this endpoint gives us a list of files on private OneDrive:

.../me/drive/root/children

Drive on SharePoint's sites works in the same way, but instead of me you should provide global Id of the site you want to access (global Id is <hostName>,<siteCollectionId>,<siteId>).

In conclusion: this endpoint gives us a list of files on a specified site's default drive:

.../Sharepoint/sites/<hostName>,<siteCollectionId>,<siteId>/drive/root/children

If you want to access files on a specific list, all you need is the id of the list:

.../Sharepoint/sites/<hostName>,<siteCollectionId>,<siteId>/lists/<listId>/drive/root/children

Now it should be obvious.



来源:https://stackoverflow.com/questions/39638790/how-to-access-a-document-library-in-a-sharepoint-online-site-using-ms-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!