OneDrive / onedrive-sdk-csharp

OneDrive SDK for C#! https://dev.onedrive.com
Other
294 stars 143 forks source link

Basic Authentication is not working... #139

Closed praveenmb9752000 closed 8 years ago

praveenmb9752000 commented 8 years ago

Getting this error "An exception of type 'Microsoft.OneDrive.Sdk.OneDriveException' occurred in mscorlib.dll but was not handled in user code" in below code... I am building a console App...

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Azure.ActiveDirectory.GraphClient; using Microsoft.Azure.ActiveDirectory.GraphClient.Extensions; using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.OneDrive.Sdk;

namespace samplapp { class Program { private static string clientId = "ca***_24"; private static string returnUrl = "http://localhost:8080/a**__gin"; private static string[] scopes = new String [] {"Files.Read", "Files.Read.All", "Files.Read.Selected", "Files.ReadWrite", "Files.ReadWrite.All", "Files.ReadWrite.AppFolder", "Files.ReadWrite.Selected", "Group.Read.All", "Group.ReadWrite.All", "IdentityRiskEvent.Read.All", "MyFiles.Read", "MyFiles.Write", "Sites.Read.All", "Sites.Search.All" }; private static string clientSecret = "eIjIywbe_*WyfCa"; private static string oneDriveApiEndpoint = "https://co******_s-my.sharepoint.com/api/v2.0/me/"; private static string serviceResourceId = "https://co*******s-my.sharepoint.com"; static void Main(string[] args) {

       calling();

    }

    static async void calling()
    {
        var oneDriveClient = BusinessClientExtensions.GetActiveDirectoryClient(
                    clientId,
                    returnUrl,
                    oneDriveApiEndpoint,
                    serviceResourceId);

        try { 
        await oneDriveClient.AuthenticateAsync();
    }
    catch(Microsoft.OneDrive.Sdk.OneDriveException e)
        {
            Console.WriteLine(e.Error);
            Console.ReadLine();

        }
        var drive = oneDriveClient
                                  .Drive
                                  .Request()
                                  .GetAsync();
        var rootItem = oneDriveClient
                         .Drive
                         .Root
                         .Request()
                         .GetAsync();

        Console.WriteLine(rootItem);
        Console.ReadLine();
    }
}

}

Can you please help me on this?

cdmayer commented 8 years ago

You are calling an async method in Main() without telling that method to run synchronously. The SDK is not compatible with that. Try checking out this StackOverflow thread about the topic.