How do i display files from a users OneDrive using the Microsoft Graph Api

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 08:37:23

问题


I'm currently working with the OneDrive API to get files from a users OneDrive.

I need to be able to display a file from OneDrive dynamically, depending on what element a user clicks on.

I Know that I can go into my OneDrive and get a Embedded Link that I can use to display a file from my OneDrive, but this is not what I need. I attempted to use the Embedded Link combined with data binding but the link requires a authorization token unique the initial embedded link.

Essentially I want a user to click on a element corresponding to a OneDrive element (eg a file or pdf). Then have file will display in a IFrame on the page.


回答1:


For Office documents, you can use the webUrl property from a DiveItem. This URL will open the document in the editor associated with that file type. For example, navigating to the webUrl for a .ppt file will open that document in PowerPoint Online.

For other files, the webUrl property simply points to the file itself. What happens when you navigate to that address will depend on the file type and what applications you have installed. Navigating to a .pdf generally will show that file in the browser (most browsers support PDF) but other files may not have an application and therefore just download to the local machine.

You can open the URLs into an iframe but be careful to ensure you're UI is taking up minimal screen area. Also make sure you're page is responsive so users can use the app in a smaller window and/or mobile device without your UI eating up so much canvas that they can't see/use the document itself.




回答2:


here is an example of a creation of an edit link in onedrive, you can change the type of edit to embeed to get what you want, this is in php utilizing laravel, the graph api with the docs https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/item_createlink

public function getEditableEmbeed($itemid){

    $this->refresh();
     $file = $this->getGraph()->createRequest("POST", "/me/drive/items/".$itemid."/createLink")->attachBody('{ "type": "edit", "scope": "anonymous"}')->execute();
     return $file;
}


来源:https://stackoverflow.com/questions/46340136/how-do-i-display-files-from-a-users-onedrive-using-the-microsoft-graph-api

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