0
votes

I'm trying to create an application which will access folders and subsequently their content through SkyDrive API.

But only things I manage to get are my name and picture. Folders are not being depicted for some unknown reason.

The code runs without mistake only output is absent. I really don't know what am i doing wrong. If somebody have any suggestions I would be immensely grateful.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>file Content</title>
    <style>

    </style>    

</head>
<body>
<h1>File Content</h1>
<div>
  <div id="meName" class="Name"></div>
  <div id="meImg"></div>
  <div id="signin"></div>
  <div bgcolor='blue' id ="meCount"></div>
</div>


<script src="//js.live.net/v5.0/wl.js" type="text/javascript" language="javascript"></script>
<script type="text/javascript" language="javascript">

    // Update the following values
    var client_id = "XXXXXXXXXX",
        scope = ["wl.signin", "wl.basic", "wl.offline_access", "wl.emails", "wl.skydrive_update"],
        redirect_uri = "http://XXXXXXXX/callback.aspx";

    function id(domId) {
        return document.getElementById(domId);
    }

    function displayMe() {
        var imgHolder = id("meImg"),
        nameHolder = id("meName"),
    cout = id("meCount");

        if (imgHolder.innerHTML != "") return;

        if (WL.getSession() != null) {
            WL.api({ path: "me/picture", method: "get" }).then(
                    function (response) {
                        if (response.location) {
                            imgHolder.innerHTML = "<img src='" + response.location + "' />";
                        }
                    }
                );



            WL.api({ path: "me", method: "get" }).then(
                    function (response) {
                        nameHolder.innerHTML = response.name;
                    }
                );

            WL.api({ path: "me/skydrive", method: "get" }).then(
                    function (response) {
                        cout.innerHTML = response.count;
                    }
                );


        }
    }



    function clearMe() {
        id("meImg").innerHTML = "";
        id("meName").innerHTML = "";
    }

    WL.Event.subscribe("auth.sessionChange",
        function (e) {
            if (e.session) {
                displayMe();
                refreshPath ();
            }
            else {
                clearMe();
            }
        }
    );




    WL.init({ client_id: client_id, redirect_uri: redirect_uri, 
              response_type: "code" });

    WL.ui({ name: "signin", element: "signin", brand: "skydrive", 
            type: "Connect", scope: "wl.signin wl.skydrive_update" });



    function refreshPath (){
                  var options = viewerPage.options;

                  var name = (options && 'name' in options) ? 
                                              options.name : 'SkyDrive';
                  var path = (options && 'path' in options) ? 
                                              options.path : 'me/skydrive';

                  loadPath(name, path);
                }

                function isFolder (file){
                  return file.type == 'folder' || 
file.type == 'album';
                }

                function loadPath(name, path){
                 updateTitle(name);
                 clearViewer();

         WL.api({path: path + '/files'}, function (response){
                  if (response.error){
                  return;
                  }

             var items = response.data.map(function (item) {

                  return{
                    group: 'default',
                    key: item.id,
                    file: item
                    };
                });

                items.sort(function itemA, itemB){
                   var isFolderA = isFolder(itemA.file);
                   var isFolderB = isFolder(itemB.file);

                   if (isFolderA == isFolderB){

return itemA.file.namelocaleCompare(itemB.file.name);
                    }
                    else if (isFolderA){
                    return -1;
                    }
                    else{
                      return 1;
                      }
                    });
                viewerPage.items = items;
                updateList();
            });
            }




    </script>

<script>

</script>
</body>
</html>
2
Hi Meks - do you have a net capture (ala F12 tools or Firebug) that has the result of the HTTP calls made to the API? - selbie
No I don't. What is a net Capture? - meks
is it what you are talking about? - meks
using Newtonsoft.Json; namespace ConsoleApplication { [JsonObject(MemberSerialization.OptIn)] public class Folder : FileSystemInfo { [JsonProperty(PropertyName = "count")] public int Count { get; set; } [JsonProperty(PropertyName = "is_embeddable")] public bool IsEmbeddable { get; set; } } } - meks

2 Answers

1
votes

Have you tried playing with the samples on the ISDK:

http://isdk.dev.live.com

For example, the following sample:

http://isdk.dev.live.com/ISDK.aspx?category=scenarioGroup_skyDrive&index=2

There's also a panel where you can play with direct calls against the Live API Service to see what they return.