如何編寫 .NET 控制台應用程序來訪問 SkyDrive? (How can I write a .NET console application to access SkyDrive?)


問題描述

如何編寫 .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 RandellNigel Findlater)

參考文件

  1. How can I write a .NET console application to access SkyDrive? (CC BY‑SA 3.0/4.0)

#onedrive #.net






相關問題

WP7-Skydrive API 下載任何文件並保存隔離存儲 (WP7-Skydrive API Download Any file and Save Isolated Storage)

如何編寫 .NET 控制台應用程序來訪問 SkyDrive? (How can I write a .NET console application to access SkyDrive?)

Loại đăng nhập Skydrive API Windows 8 (Skydrive API login type Windows 8)

如何使用 Rest api 和 oauth2.0 創建文件夾和上傳文件 (How to create folder and upload file using Rest api and oauth2.0)

從 ERP 保存到 OneDrive (Save to OneDrive from ERP)

適用於 Windows 通用 APP 的 OneDrive Api (OneDrive Api for Windows Universal APP)

一種 Drive / Office365 與 Google Apps Script 類似的腳本語言 (One Drive / Office365 similar scripting language as the Google Apps Script)

OneDrive API 瀏覽器 C# (OneDrive API browser C#)

從 Python 應用程序訪問 Microsoft Live 服務 (Access Microsoft Live services from Python application)

一個驅動器 api 安全 URL (One drive api secure url)

嘗試使用 get-PnPFile 從 OneDrive 獲取文件的所有版本時找不到文件 (File not found trying to get all versions of a file from OneDrive using get-PnPFile)

一個驅動器遷移 (One Drive Migration)







留言討論