Microsoft Graph get filename

删除回忆录丶 提交于 2020-07-23 16:07:02

问题


Currently stuck with getting the filename of a ressource from SharePoint online aka Office 365. Authentication and refresh token is from the Unified Api example aka Microsoft Graph.

var authResult = await authContext.AcquireTokenByAuthorizationCodeAsync(   
...
var imgBytes = await httpClient.GetByteArrayAsync(parameters.FileGet);
return File(imgBytes, "application/specialFormat", "File1.specialFormat");

At the moment I have to define my own filename. I' ve already seen the example at http://graph.microsoft.io/en-us/docs/overview/overview, but the "GET my files" example shows only how to get the files of one person and not how to get a filename based upon a file Id. I hope someone could clarify this.

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

Is getting a filename based upon the file id with the Graph api possible or do I have to use something else?

EDIT Some queries that would work:

https://graph.microsoft.com/v1.0/me/drive/root/children?$select=id
https://graph.microsoft.com/v1.0/me/drive/root/children?$filter=name eq 'testfile.office'

But if I try to search for the specific id the query fails and I get none information.

 https://graph.microsoft.com/v1.0/me/drive/root/children?$filter=id eq '01QXOQU7OCV7FW2BQNAZD3KNZMYXVMNJD6'

回答1:


If you have the item ID, you can access the item like this: https://graph.microsoft.com/v1.0/me/drive/items/ID

If you have the path, you can access the item like this: https://graph.microsoft.com/v1.0/me/drive/root:/FOLDER/FOLDER/FOLDER/FILENAME.EXT

You can further get the children of an item by path: https://graph.microsoft.com/v1.0/me/drive/root:/FOLDER/FOLDER/FOLDER/FILENAME.EXT:/children

The Drive API exposed through MS Graph is pretty much (if not exactly) the same as the API exposed by OneDrive. See this reference page: https://dev.onedrive.com/resources/item.htm



来源:https://stackoverflow.com/questions/36844437/microsoft-graph-get-filename

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