我如何登录Onedrive。 [英] How do I sign into Onedrive.
本文介绍了我如何登录Onedrive。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试登录Onedrive。我已下载Live SDK并添加引用。
这是我的代码:
I am trying to sign into Onedrive. I have downloaded Live SDK and "add reference" to it.
Here is my code:
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.
推荐答案
第一条错误消息不能是任何更清楚的方法:你试图在一个没有标记为async
的方法中使用等待
。该消息甚至告诉您如何修复错误!
MicrosoftAccountOAuth
类似乎是这个项目 [ ^ ],不是核心SDK的一部分。您是否添加了对项目的引用,以及在代码顶部使用MicrosoftAccount.WindowsForms; 指令的?
LoginAuthorizationCodeFlowAsync
方法 [ ^ ]不返回任务< string>
- 它返回任务< AppTokenResult>
。您需要更新方法签名和appToken
变量才能匹配。
The first error message couldn't be any clearer: you're trying to useawait
in a method which isn't marked asasync
. The message even tells you how to fix the error!
TheMicrosoftAccountOAuth
class appears to be part of this project[^], not part of the core SDK. Have you added a reference to the project, and ausing MicrosoftAccount.WindowsForms;
directive at the top of your code?
TheLoginAuthorizationCodeFlowAsync
method[^] doesn't return aTask<string>
- it returns aTask<AppTokenResult>
. You will need to update your method signature andappToken
variable to match.
这篇关于我如何登录Onedrive。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文