2012-06-25 50 views
8

有誰知道如何獲取特定SkyDrive文件夾的文件列表?目前我使用下面的代碼片斷,試圖讓該文件的根SkyDrive文件夾:從SkyDrive文件夾(Windows Phone)獲取文件列表

var client = new LiveConnectClient(e.Session); 

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

client.GetAsync("me/skydrive"); 

但所有的返回是一個包含大量的信息,但沒有文件名列表的結果字典!

回答

3

越來越絕望和提出問題here

原來的獲取從根SkyDrive文件夾的文件列表,你需要使用特殊的字符串之後我/的SkyDrive /文件,而不是隻是我還是我嗎/ skydrive

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     
     } 

希望這有助於。

+0

不起作用:我得到一個e.Result KeyNotFoundException [「數據」] – Calanus

+0

是的,我要求它列出根SkyDrive文件夾,即我的文件/ skydrive – Calanus

+0

你可以遍歷你的字典,並看到它包含的鍵。 – MBen

10

根據OneDrive core concepts(之前爲SkyDrive),您有兩個選項來列出文件,無論是在頂層目錄還是在特定文件夾中。當你找到了,你可以在GetCompleted事件中使用

liveClient.GetAsync("me/skydrive/files"); 

,以及所使用folderId + "/files"一個特定的文件夾,例如

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

榜前文件,您可以從數據中重點列出所有文件

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 
    } 
} 
3

MS確實不能很好地記錄實時內容API。

  1. 獲得root文件夾內容使用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

哪裏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(); 
    } 
} 
+0

你應該格式化你的代碼。現在它是不可讀的。 – kazanaki

相關問題