Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to sign into Onedrive. I have downloaded Live SDK and "add reference" to it.
Here is my code:
C#
private const string msa_client_id = "00000000xxxyyyzzz";
private const string msa_client_secret = "aaabbbcccdddeeefffggg";
private string GetOneDriveRootListing()
{
   var accessToken = GetAccessToken();
   string jsonData;
   string url = string.Format(@"https://apis.live.net/v5.0/me/skydrive?access_token={0}", accessToken);
   using (var client = new WebClient())
   {
      var result = client.OpenRead(new Uri(url));
       var sr = new StreamReader(result);
      jsonData = sr.ReadToEnd();
   }

   return jsonData;
}
private string GetAccessToken()
{
    string appToken = null;
    appToken = await MicrosoftAccountOAuth.LoginAuthorizationCodeFlowAsync(msa_client_id, msa_client_secret, new[] { "wl.offline_access", "wl.basic", "wl.signin", "onedrive.readwrite" });
    return appToken;
}

I am getting an error in everything at "await" and after.
Error code:
The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task<string>'.

and
The name 'MicrosoftAccountOAuth' does not exist in the current context.
Posted
Updated 23-Apr-15 6:47am
v3

1 solution

The first error message couldn't be any clearer: you're trying to use await in a method which isn't marked as async. The message even tells you how to fix the error!

The MicrosoftAccountOAuth class appears to be part of this project[^], not part of the core SDK. Have you added a reference to the project, and a using MicrosoftAccount.WindowsForms; directive at the top of your code?

The LoginAuthorizationCodeFlowAsync method[^] doesn't return a Task<string> - it returns a Task<AppTokenResult>. You will need to update your method signature and appToken variable to match.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900