从SkyDrive文件夹获取文件列表(Windows Phone)

时间:2012-06-25 08:34:31

标签: c# windows-phone-7 onedrive

有谁知道如何获取特定SkyDrive文件夹的文件列表?目前我正在使用以下代码片段来尝试获取根SkyDrive文件夹的文件:

var client = new LiveConnectClient(e.Session);

client.GetCompleted += (obj, arg) =>
     {
      ...
     }

client.GetAsync("me/skydrive");

但它返回的只是一个Result字典,其中包含大量信息但没有文件名列表!

4 个答案:

答案 0 :(得分:10)

根据OneDrive core concepts(以前的SkyDrive),您可以在顶层目录或特定文件夹中列出两个文件列表。如您所知,您可以使用

列出顶级文件
liveClient.GetAsync("me/skydrive/files");

,对于您使用folderId + "/files"的特定文件夹,例如

liveClient.GetAsync(folder.Id + "/files");

GetCompleted事件中,您可以列出数据密钥中的所有文件

private void onFilesInformationDownloaded(object sender,
                                          LiveOperationCompletedEventArgs e) {
    if (e.Result == null) {
        // check e.Error for reason why it failed
        return;
    }
    List<object> data = (List<object>)e.Result["data"];
    foreach (IDictionary<string, object> content in data) {
        string type = (string)content["type"];
        if (type == "folder") {
            // do something with folders?
        }
        string filename = (string)content["name"];
        string fileId = (string)content["id"];
        // use fileId to download a file or list files in a folder

        // there's a few more details available in content.Keys
        // such as created_time and updated_time for those interested
    }
}

答案 1 :(得分:3)

绝望之后问here

事实证明,要从根skydrive文件夹中获取文件列表,您需要使用魔术字符串me / skydrive / files而不仅仅是我或我/ skydrive

答案 2 :(得分:3)

MS不能很好地记录实时内容API。

  1. 要获取根文件夹内容,请使用URI:https://apis.live.net/v5.0/me/skydrive/files?access_token=“+ accessToken
  2. 对于任何其他文件夹内容,请使用URI:https://apis.live.net/v5.0/folder.4ab680998d14f4e7.4AB680998D14F4E7!110/files?access_token=“+ 的accessToken
  3. folder.4ab680998d14f4e7.4AB680998D14F4E7!110是您要列出的目标文件夹。

    Java代码示例:

    public void listRootFolder(String accessToken) {
        String folderId = "folder.4ab680998d14f4e7.4AB680998D14F4E7!110/files";
        String url = "https://apis.live.net/v5.0/" + folderId + "?access_token=" + accessToken;
        HttpMethod method = new GetMethod(url);
        HttpClient client = new HttpClient();
        try {
            int returnCode = client.executeMethod(method);
            System.out.println("Return code " + returnCode);
            System.out.println(method.getResponseBodyAsString());
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

答案 3 :(得分:0)

您的文件是否直接位于“me / skydrive”下?否则,您需要使用client.GetAsync("me/skydrive/YOURFOLDER");

进行调用

然后使用键data在结果字典中对输出进行数据处理。 你可以在completedEvent处理程序中使用这段代码来获取它:

       var data = (List<object>)e.Result["data"];
       foreach (IDictionary<string, object> content in data)
       {                   
           var skyContent = new SkyDriveContent();
           skyContent.Name = (string)content["name"];
           ContentList.Add(skyContent);    // where ContentList is :     List<SkyDriveContent> ContentList = new List<SkyDriveContent>(); in your class                
       }

希望这有帮助。