Looks like the Onedrive API exposed by Microsoft has changed. A little bit of context. In order to use the shareable link that onedrive provide we need to convert that link to a direct one.
Will detail step by step how to get the link:
- Go to Onedrive, create a file and share for everyone so no sign-in is required (at least is what is showed in the UI of Onedrive)
So you will get this: https://1drv.ms/x/c/0544626922291d4d/ESHLSHTfi9FLm6ZskvL3yc0BvkFv4n92Q5fiIxttWk0ybg?e=BW9JH8
We need a code or in someway translate the URL provided to have a new one that should start with https://api.onedrive.com/v1.0/shares/u!
So, a code in Python that could help us, is:
import base64
async def create_onedrive_directdownload(onedrive_link):
data_bytes64 = base64.b64encode(bytes(onedrive_link, 'utf-8'))
data_bytes64_string = data_bytes64.decode('utf-8').replace('/', '_').replace('+', '-').rstrip("=")
result_url = f"https://api.onedrive.com/v1.0/shares/u!{data_bytes64_string}/root"
return result_url
In addition, I used to have this code but looks like since 3/25 did stop working.
I already implemented a code as I showed but no luck. Now what I get after I run that method and a new URL is generated.
The call is showing:
{"error":{"code":"unauthenticated","message":"The caller is not authenticated."}}
