Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of files from SkyDrive folder (Windows Phone)

Does anyone know how to get a list of files for a particular SkyDrive folder? Currently I'm using the following snippet to try and get the files for the root SkyDrive folder:

var client = new LiveConnectClient(e.Session);

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

client.GetAsync("me/skydrive");

but all it returns is a Result dictionary that contains a lot of info but no list of filenames!

like image 533
Calanus Avatar asked Jun 25 '12 08:06

Calanus


3 Answers

According to OneDrive core concepts (previously SkyDrive) you have two options to list files, either in the top directory or a specific folder. As you found out, you can list the top files using

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

and for a specific folder you use folderId + "/files", for example

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

in the GetCompleted event you can list all files from the data key

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
    }
}
like image 156
Patrick Avatar answered Nov 12 '22 01:11

Patrick


After getting desperate and asking the question here

it turns out the to get a list of files from the root skydrive folder you need to use the magic string me/skydrive/files rather than just me or me/skydrive

like image 26
Calanus Avatar answered Nov 12 '22 03:11

Calanus


It is really bad that MS does not document well the live content API.

  1. To get root folder contents use URI: https://apis.live.net/v5.0/me/skydrive/files?access_token=" + accessToken
  2. For any other folder contents use URI: https://apis.live.net/v5.0/folder.4ab680998d14f4e7.4AB680998D14F4E7!110/files?access_token=" + accessToken

Where folder.4ab680998d14f4e7.4AB680998D14F4E7!110 is the target folder you want to list.

Java code sample:

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();
    }
}
like image 3
Yosi Lev Avatar answered Nov 12 '22 03:11

Yosi Lev