OneDrive File Picker JavaScript SDK v7.2 action download does not work

Preeti Jain 16 Reputation points
2022-10-18T06:05:26.117+00:00

I am using OneDrive File Picker JavaScript SDK v7.2, with download action, to select files from sharepoint

My picker options are as follows:

   const options = {  
        clientId: "<my client id>",  
        action: "download",  
        multiSelect: false,  
        advanced: {  
            endpointHint: "https://<my tenant>.sharepoint.com/sites/<sitename>/Shared%20Documents/",  
            accessToken: <oAuth token>,  
        },  
        success:  function() {   
            console.log(JSON.stringify(files));  
         },   
        cancel: function() {   
            //  
         },  
        error: function(error) { /* error handler */ }  
      }  

I am able to load the file picker and select a file. But after selecting the a file I am getting the following error in the response:

response
:
"{\"error\":{\"code\":\"unauthenticated\",\"innerError\":{\"code\":\"invalidAudienceUri\"},\"message\":\"Invalid audience Uri '00000003-0000-0000-c000-000000000000'.\"}}"

I have used Microsoft Graph API to get the access token.

Microsoft 365 and Office SharePoint Development
Microsoft Security Microsoft Graph
{count} votes

2 answers

Sort by: Most helpful
  1. CarlZhao-MSFT 46,371 Reputation points
    2022-10-18T07:30:48.02+00:00

    Hi @Preeti Jain

    You should use the SharePoint API instead of the Graph API to get tokens, change your scope to: https://<my tenant>.sharepoint.com/.default.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. CarlZhao-MSFT 46,371 Reputation points
    2022-10-18T09:00:45.547+00:00

    Hi @Preeti Jain

    If you must use the Graph API to access shared documents in the site, simply change the SharePoint API endpoint in the script to the Graph API endpoint.

    endpointHint: https://graph.microsoft.com/v1.0/sites/{site id}/drive/root/children  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.