I am successfully returning search results from a user's OneDrive for Business account using the https://graph.microsoft.com/v1.0/me/drive/root/microsoft.graph.search endpoint.
I am using those results in a federated search within our application and would like to use the api to render thumbnails for each item when available.
I have an access token for the https://graph.microsoft.com resource and everything is working well except thumbnails.
I am able to get the thumbnail collection data back, for example:
[small] => Array(
[height] => 350
[width] => 266
[url] => https: //xxxxxxxxxxx-my.sharepoint.com/personal/xxxxxxxxxxxxxxxxx_onmicrosoft_com/_api/v2.0/drive/items/{item id}/thumbnails/0/small/thumbnailContent )
Any attempts to access that thumbnailContent url either directly in an img tag or via curl return errors. For the curl, I am supplying the access token in the header.
I receive error information like:
HTTP/1.1 403
X-MSDAVEXT_Error: 917656; Access+denied.+Before+opening+files+in+this+location%2c+you+must+first+browse+to+the+web+site+and+select+the+option+to+login+automatically.
{"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":"Access denied. You do not have permission to perform this action or access this resource."}}
Any help would be appreciated in solving what is required here.
I have read I may need a sharepoint token instead of a graph token. If that is the case, I can't seem to figure out how to get the resource id I need to request the necessary sharepoint token.
Thank you.
The Graph devs assure us that unathetnicated thumbnail URL's are coming, as per the issue posted here (which I started) github.com/OfficeDev/microsoft-graph-docs/issues/135. In the meantime, you can follow the workaround that I hinted at there, which it looks like you're attempting to do. As you noted, you'll need to supply an access token for the onedrive API, which is not the same as an access token for the Graph API. You should check out the relevant OneDrive API documentation, but I think it boils down to being the case that the "resource ID" you're looking for is just the base URL for your OneDrive, e.g. https://contoso-my.sharepoint.com/
. You can actually just parse this out of the thumbnail URL itself. If you happen to be doing all this from JavaScript, I'd recommend looking at Adal.js if you're not already.
You should be able to use your OneDrive API access token to make the thumbnailContent request. If you request a responseType
of blob
, you can then use FileReader.readAsDataURL
(again, assuming you're in JavaScript) to get a data URL that can sit in an image tag.
Been a while since I looked at all this, but this was the workaround that I had working as of whenever I posted in that issue link. Hope it helps.