如何利用OneDrive API的代码流?
如何允许我的C#应用程序(非表单 ,非基于Web )应用程序进行身份validation并与OneDrive交互? (也就是说, 完全以编程方式。)
至今:
– 已注册应用程序,具有客户端ID和密码。
– 启用网络和电话。
– 个人而非商业。
-Client 令牌流似乎是交互式的,因此使用代码 。
– 使用OneDrive SDK,但它只是说它无法进行身份validation(不是为什么)。 – 现在滚动请求。
作为Web客户端代码:
async Task GetStringFromURLAsync(string theURL) { string urlContents = ""; System.Net.Http.HttpClient c = null; try { c = new System.Net.Http.HttpClient(); c.Timeout = new System.TimeSpan(0, 0, 30); // 30 seconds Task asyncResp = c.GetStringAsync(theURL); urlContents = await asyncResp; Console.WriteLine("success..."); } [catch...] return urlContents; }
被称为:
Task tGetContent = GetStringFromURLAsync(ai.fullTokenRequestURI); string httpResponseBody = tGetContent.Result;
(ai是一个持有客户端ID,url等的结构)
如果无法自行滚动并获得正确的响应,那么我应该使用哪个SDK?
这不是更好:
this.oneDriveClient = OneDriveClient.GetMicrosoftAccountClient( authInfo.cient_id, authInfo.redirect_url, authInfo.scopes); await this.oneDriveClient.AuthenticateAsync();
OD API只是抱怨:
OneDrive reported the following error: Code: AuthenticationFailure Message: Failed to retrieve a valid authentication token for the user.