1

I have a public folder stored in my personal OneDrive account, which contains several files. The link to this folder is in the form: https://1drv.ms/f/c/{driveId}/{hereThereIsALongIdWithNumbersAndLetters001} (i changed the actual ids for privacy reasons). When I navigate to it in an incognito window, I can see the content without any issue. Now, the thing is that there are so many files that they are not loaded all at once, but they load dynamically as I scroll down the page. In the browser's element inspector I noticed that the web make requests (one at the beginning and the rest as I scroll down) to obtain a JSON with the data of the files that are displayed. This request is in the form: https://my.microsoftpersonalcontent.com/_api/v2.0/drives/{driveId}/items/{anotherIdHere}/children?%24top=100&orderby=folder%2Cname&%24expand=thumbnails%2Ctags&select=*%2Cocr%2CwebDavUrl%2CsharepointIds%2CisRestricted%2CcommentSettings%2CspecialFolder%2CcontainingDrivePolicyScenarioViewpoint&ump=1 . I would like to use that URL inside a UrlFetchApp.fetch() request in Google Apps Script to restrieve the JSON. The thing is that up to several months ago this worked like charm, but for some reason it stopped working and now I get:

{
  "error": {
    "code": "unauthenticated",
    "message": "Unauthenticated"
  }
}

The code I was using is:

var json = JSON.parse(UrlFetchApp.fetch(url).getContentText()).value

So far, I tried copying the fetch request directly from the browser's element inspector (in Chrome, under the Network tab of the element inspector, I looked for a "children?%24top=100&..." request, then right click and "Copy as fetch") and then using it "as is" in the UrlFetchApp.fetch() function, but instead of the previous error I got a new one:

{
    "error":{
        "code":"corsBypassFailure",
        "message":"Failed to unpack request: Content-Length is out of range (0)"
    }
}

I tried then to add the "Content-Length" manually, copying the value from the header of the element inspector, but another error was shown:

Exception: Attribute provided with invalid value: Header:Content-Length

I noticed that the URL to get the JSONs has changed during this time. Now they are in the form https://my.microsoftpersonalcontent.com/_api/v2.0/drives/{driveId}/items/{anotherIdHere}/children?%24top=100&orderby=folder%2Cname&%24expand=thumbnails%2Ctags&select=*%2Cocr%2CwebDavUrl%2CsharepointIds%2CisRestricted%2CcommentSettings%2CspecialFolder%2CcontainingDrivePolicyScenarioViewpoint&ump=1 (as I mentioned before), but when it worked they used to be in the form https://api.onedrive.com/v1.0/drives('{driveId}')/items('{anotheIdHere}')/children?%24top=100&%24expand=thumbnails%2Clenses%2Ctags&ump=1&authKey=!AIwLXlk3hfSEL7c&%24select=*%2Cocr%2CwebDavUrl%2CsharepointIds%2CisRestricted%2CcommentSettings%2CspecialFolder%2CcontainingDrivePolicyScenarioViewpoint&%24skiptoken=MTAx&%24orderby=folder%2Cname . It seems that Microsoft has deprecated v1.0 API or something.

I also tried to use Azure Apps Registry to get an OAuth2 token that I could use in Google Apps Script, but requires a paid subscription.

Anyone knows how can I get my code to work again without using API keys or anything (just as before)?

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.