Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download OneDrive file from cURL since they've changed their URL's construction

here's the problem i have.Before OneDrive changed the url's it was easy to force a file to be downloaded from cURL, but now since they've changed their URL's construction i can't use the previous approach of replacing redir? with download?. That's how they used to be constructed:

https://onedrive.live.com/redir?resid=

To make it start downloading immediately we just had to replace the redir with download like this

https://onedrive.live.com/download?resid=

and that was fixing it at all, but now the url's are like this:

https://1drv.ms/u/s!AsdMSpdm_dmsadMSda

So, my question is how can i download the file from cURL, i cannot do that even with CURLOPT_FOLLOWLOCATION, it is only working if the file is forced to be downloaded. Thanks in advance!

like image 764
Simeon Avatar asked Dec 24 '22 04:12

Simeon


1 Answers

There are two options. The "right" way to do this would be to encode the full sharing URL following the details described here https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/shares_get?view=odsp-graph-online#encoding-sharing-urls and then construct a URL like this:

https://api.onedrive.com/v1.0/shares/{encodedUrl}/root/content

Which will download the contents of the shared file at the URL. Option #2 is to splice the URL up and grab the path segment that starts with s! and just use that in the same place as the encoded Url:

https://api.onedrive.com/v1.0/shares/s!.../root/content

Either way, you can then use cURL to download the content of the file.

like image 125
Ryan Gregg Avatar answered Dec 28 '22 05:12

Ryan Gregg