Search code examples
apimicrosoft-graph-apionedrive

OneDrive Microsoft Graph error : Token contains invalid signature


I'm trying to access the list of files in my OneDrive for Business drive.

I followed the "Code Flow" approach and I got to the point where I already have the token and was able to get my endpoint via https://graph.microsoft.com/v1.0/me?$select=mySite

But when I try to list the files, using MyEndpoint/_api/v2.0/me/drive/root/children I get the error:

{"error":{"code":"unauthenticated","message":"Token contains invalid signature.","innerError":{"code":"invalidSignature"}}}

If I put the full url in the browser I get the JSON result (after authenticating).

Help?


Solution

  • Instead of using MyEndpoint/_api/v2.0/me/drive/root/children, you can use MS Graph REST API to list files in a users OneDrive by sending a GET request to https://graph.microsoft.com/v1.0/me/drive/root/children. The request should contain a header with the token with one of the permissions listed at https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_list_children.

    Also, the Graph explorer has plenty of OneDrive samples that are worth checking. To see the OneDrive samples click the show more samples link.

    enter image description here