如何利用OneDrive API的代码流?

时间:2016-07-06 16:53:01

标签: c# onedrive

如何允许我的C#应用​​程序(非表单,非基于Web的)应用程序进行身份验证&与OneDrive交互? (也就是说,完全以编程方式。)

到目前为止:

- 已注册申请,拥有客户ID和秘密。
- 启用web和&电话。
- 个人而非商业 -Client token 流似乎是用于交互式的,因此使用代码
- 使用OneDrive SDK,但它只是说它无法进行身份验证(不是为什么)。 - 现在滚动请求。

作为网络客户端代码:

    async Task<string> 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<string> asyncResp = c.GetStringAsync(theURL);
            urlContents = await asyncResp;
            Console.WriteLine("success...");
        }
        [catch...]
        return urlContents;
    }

被叫:

    Task<string> 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.

0 个答案:

没有答案