OneDrive download link to a direct link not working, auth requested

23 views Asked by At

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:

  1. 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)

enter image description here

  1. So you will get this: https://1drv.ms/x/c/0544626922291d4d/ESHLSHTfi9FLm6ZskvL3yc0BvkFv4n92Q5fiIxttWk0ybg?e=BW9JH8

  2. 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!

  3. 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."}}

Any ideas to avoid using any kind of auth.

0

There are 0 answers