我正在尝试创建一个应用程序,该应用程序将通过 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>