0

我想覆盖 OneDrive 上的文件。

我认为下面是正确的方法,但我看不到我会在哪里为我的 OneDrive 帐户提供登录凭据。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Live;
using System.IO;
using System.Threading.Tasks;



namespace OneDriveUpdater
{
    class Program
    {
        static void Main(string[] args)
        {   

            LiveConnectClient liveClient = new LiveConnectClient(this.session);

            FileStream fs = new StreamReader(@"c:\status.txt");

            var result = await liveConnectClient.UploadAsync("", "STATUS", fs, OverwriteOption.Overwrite);


        }      

    }
}
4

2 回答 2

1

文档有点稀疏,但如果你看的话,信息就在那里。我没有对此进行测试 - 它纯粹基于文档,但看起来大致正确。

创建一个LiveAuthClient实例,并调用 a LoginorInitialize方法进行身份验证(似乎Initialize会以静默方式进行身份验证,但Login必要时会显示一个对话框)。

无论您选择哪种方法,任务完成时的返回值都是一个LiveLoginResult实例。它具有连接状态的.Session属性和 type的属性LiveConnectSession

.Session值是您需要传递给LiveConnectClient构造函数的值。

于 2014-09-24T15:30:44.487 回答
0

尝试使用此代码首次登录用户:

using Microsoft.Live;
private LiveConnectSession _session = null;

public async Task AuthenticateUserThroughLive()
{
  try
  {
      LiveAuthClient LCAuth = new LiveAuthClient("<Redirect Domain>");

      LiveLoginResult loginResult = await LCAuth.LoginAsync(new string[] { "wl.signin", "wl.basic", "wl.skydrive", "wl.skydrive_update" });
      if (loginResult.Status == LiveConnectSessionStatus.Connected)
      {
          this.LiveSession = loginResult.Session;
      }
  }
  catch (LiveAuthException)
  {
     // Handle exceptions.
  }
}

从您在 Live Connect 管理站点中设置应用程序的方式替换重定向域,并在 Login() 方法中仅传递所需的范围。Session 属性包含您与 Live Connect 对话所需的身份验证令牌,授予用户允许您通过 Scopes 访问 OneDrive 的权限。

PS:我刚刚写了一篇关于相关主题的文章。如果相关,请查看http://developer.telerik.com/featured/live-connect-integration-mobile-apps/ 。

谢谢!

于 2014-09-25T03:12:10.183 回答