Search code examples
c#microsoft-graph-onenote

View onenote folder and files


I am trying to get existing files in one note and I keep getting a generic error that doesn't have any details , Exception of type 'Microsoft.Graph.Models.ODataErrors.ODataError' was thrown.

        var clientId = "client";
        var tenantId = "tenant";
        var clientSecret = "secret";
        var clientSecretCredential = new ClientSecretCredential(
            tenantId, clientId, clientSecret);

        var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
        var sharedDriveItems = await graphClient.Drives.GetAsync(); //fails on this

I've set up a key and confirmed the values on portal.azure.com and I've set up the read permissions for microsoft graph. Is there anyway to get a more detailed error message or something to double check to get rid of the error?


Solution

  • To get detailed error messages:

    try
    {
        var sharedDriveItems = await graphClient.Drives.GetAsync(); //fails on this
    }
    catch (ODataError odataError)
    {
        Console.WriteLine(odataError.Error.Code);
        Console.WriteLine(odataError.Error.Message);
    }