問題描述
如何編寫 .NET 控制台應用程序來訪問 SkyDrive? (How can I write a .NET console application to access SkyDrive?)
I'm trying to work out how to create a simple .NET console application to access skydrive so I can send and receive files from a command line.
The Live Connect SDK and documentation appears to be a little vague and generally targeted at Metro or HTML apps.
If someone knows how to authenticate and then list the contents, which I think should be simple, then the rest will probably be easy.
Ideally I would like to use an API, but if I have to revert to driving the REST API, that is ok as well.
Here's a block of code I'm trying to use
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Live;
namespace SkyDriveCmd
{
class Program
{
static void Main(string[] args)
{
try
{
var task = Run();
task.Wait();
}
catch (Exception ex)
{
Console.Error.WriteLine(ex);
}
}
private static async Task Run()
{
var auth = new LiveAuthClient("XXXXXXXXXXXXX");
var client = new LiveConnectClient(auth.Session);
var result = await client.GetAsync("/");
Console.WriteLine(result.RawResult);
}
}
}
I know this is wrong as auth.Session is null, but I'm finding a massive lack of documentation around how this could work.
‑‑‑‑‑
參考解法
方法 1:
Here is an example using an Api downloaded from http://skydriveapiclient.codeplex.com/releases/view/103081
static void Main(string[] args)
{
var client = new SkyDriveServiceClient();
client.LogOn("YourEmail@hotmail.com", "password");
WebFolderInfo wfInfo = new WebFolderInfo();
WebFolderInfo[] wfInfoArray = client.ListRootWebFolders();
wfInfo = wfInfoArray[0];
client.Timeout = 1000000000;
string fn = @"test.txt";
if (File.Exists(fn))
{
client.UploadWebFile(fn, wfInfo);
}
}
(by Nick Randell、Nigel Findlater)