Reputation: 73
I'm trying to generate embed links in OneDrive personal via the Rest API. I'm using the function createLink (link). I am able to generate a link, but opening this link in a browser gives me a "Sorry, something went wrong" error.
If I log on to OneDrive via a browser, I can see that the file is now shared, and has an embed link. The same link that was returned via the API. This link is formatted as:
https://onedrive.live.com/embed?resid=abcdef&authkey=123456
However, if i click the embed button, I get a longer, differently formatted link:
https://yfzapq.am.files.1drv.com/abcdefg123456?height=504&width=504
This link works perfectly. Paste it in to any browser, and it will download the file - No questions asked!
So my question is how to get a hold on this second link via the Rest API?
Upvotes: 1
Views: 725
Reputation: 451
Met the same problem. I've looked up how exactly onedrive is getting embed url when you use "Embed" on website. Turned out it uses other function than createLink - it uses /thumbnails.
And you can also use this function as it is a part of Rest API - as result you'll get links in format https://yfzapq.am.files.1drv.com/abcdefg123456?width=768&height=1024&cropmode=nonethat that seems to last forever. If you remove all the parameters from url (?width=768&height=1024&cropmode=none
) it will lead to the original image.
PS The problem with this method - thumbnail urls are dying within 4 hours (from my experience).
Method described above stopped working, now it returns just dead urls. The current solution I'm using instead is GET /me/drive/items/{item-id}/content. It redirects to the page where you can download the file. But what you also can do is to disable redirects for this request and get the direct url for the requested file (from the "Location" header).
Sure, it won't last forever but this method could be used if you need to reupload files from google drive elsewhere without actually downloading them and providing url to upload from instead.
Upvotes: 0