【发布时间】:2013-11-25 10:05:41
【问题描述】:
我正在使用 Skydrive API,我希望我的用户能够打开一个关于文件的视图,您可以在其中编辑它(与您在 Skydrive 网络上时我们可以看到的文件视图相同)页)。
它可能有 WL 功能,但我找不到。另一种解决方案是让我获取视图页面的 URL 并使用 javascript 在新窗口中打开它。
【问题讨论】:
标签: javascript api onedrive
我正在使用 Skydrive API,我希望我的用户能够打开一个关于文件的视图,您可以在其中编辑它(与您在 Skydrive 网络上时我们可以看到的文件视图相同)页)。
它可能有 WL 功能,但我找不到。另一种解决方案是让我获取视图页面的 URL 并使用 javascript 在新窗口中打开它。
【问题讨论】:
标签: javascript api onedrive
我已经使用 SkyDrive 及其 API 实现了这个解决方案。您也可以在Microsoft's Interactive Live SDK 在线工具中试用此脚本。关键是为您要打开的文件获取 SkyDrive 的重定向链接。 Get api 的 json 结果中的每个文件都会返回此重定向链接。
WL.init({ client_id: clientId, redirect_uri: redirectUri });
WL.login({ "scope": "wl.skydrive" }).then(
function(response) {
getFiles();
},
function(response) {
log("Could not connect, status = " + response.status);
}
);
function getFiles() {
var files_path = "/me/skydrive/files";
WL.api({ path: files_path, method: "GET" }).then(
onGetFilesComplete,
function(response) {
log("Cannot get files and folders: " +
JSON.stringify(response.error).replace(/,/g, ",\n"));
}
);
}
function onGetFilesComplete(response) {
var items = response.data;
var foundFolder = 0;
for (var i = 0; i < items.length; i++) {
if (items[i].type === "file" &&
items[i].name === "robots.txt") {
log("Found a file with the following information: " +
JSON.stringify(items[i]).replace(/,/g, ",\n"));
foundFolder = 1;
//open file in a new browser window
window.open(items[i].link);
break;
}
}
if (foundFolder == 0) {
log("Unable to find any file(s)");
}
}
function log(message) {
var child = document.createTextNode(message);
var parent = document.getElementById('JsOutputDiv') || document.body;
parent.appendChild(child);
parent.appendChild(document.createElement("br"));
}
【讨论】: