我正在尝试创建一个将通过SkyDrive API访问文件夹及其内容的应用程序。

但是只有我设法得到的是我的名字和照片。由于某些未知原因,未显示文件夹。

该代码无误运行,仅缺少输出。我真的不知道我在做什么错。如果有人有任何建议,我将不胜感激。

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

最佳答案

您是否尝试过使用ISDK上的示例:

http://isdk.dev.live.com

例如,以下示例:

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

还有一个面板,您可以在其中对Live API Service进行直接调用,以查看它们返回的内容。

10-01 06:34