有人知道如何获取特定SkyDrive文件夹的文件列表吗?目前我正在使用以下代码片段尝试获取根SkyDrive文件夹中的文件:
var client = new LiveConnectClient(e.Session);
client.GetCompleted += (obj, arg) =>
{
...
}
client.GetAsync("me/skydrive");
但是它返回的只是一个Result字典,其中包含很多信息,但没有文件名列表!
有人知道如何获取特定SkyDrive文件夹的文件列表吗?目前我正在使用以下代码片段尝试获取根SkyDrive文件夹中的文件:
var client = new LiveConnectClient(e.Session);
client.GetCompleted += (obj, arg) =>
{
...
}
client.GetAsync("me/skydrive");
根据OneDrive核心概念(以前是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
}
}
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();
}
}
client.GetAsync("me/skydrive/YOURFOLDER");
来调用它。data
的Result字典中。
在完成事件处理程序中,你可以使用以下代码来获取它: 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
}