1
votes

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.

1
Hi Ray - I was looking at the GitHub repo to see if there were any issues and it looks like there is. A comment 7 days ago shows they disabled the pre-authenticated urls. I would follow this thread and maybe add some comments to it. github.com/OfficeDev/microsoft-graph-docs/issues/135jdruid
Thanks, I saw that... I have been trying send properly authenticated requests for each thumbnail url thinking maybe I need a sharepoint token, but have been unsuccessful. Are pre-authenticated urls the only option?Raymond Baranoski
I've also tried building the getpreview.ashx url as described in this post link, and it works, but I'm having issues on first load, where it seems to be not authenticated yet, but if I "view image" from the browser, that triggers an auth step and I'm good for my session. I can probably hack this to work, but it doesn't feel production ready and I'm relying on that url syntax...Raymond Baranoski

1 Answers

0
votes

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.