我正在使用Skydrive文件选择器javascript api将文件上传到Skydrive。但是一旦我点击上传按钮......它就会打开登录窗口并立即关闭。错误日志显示WL.login:弹出窗口未经任何同意而关闭。
我在本地域托管了我的网络应用程序:apidomain并将我的文件发布到IIS @ Default网站/ onedriveapi文件夹。
以下是代码:
[HTML]
<button onclick="uploadFile()">Save file</button>
<label id="info"></label>
[使用Javascript]
<script src="//js.live.net/v5.0/wl.js" type="text/javascript"></script>
<script type="text/javascript">
WL.init({
client_id: "00000000XXXXXXXX",
redirect_uri: "http://apidomain.com/onedriveapi/default.html",
scope: ["wl.signin", "wl.skydrive", "wl.skydrive_update"],
response_type: "token"
});
function uploadFile() {
WL.login({
scope: "wl.skydrive_update"
}).then(
function (response) {
alert(response);
WL.upload({
//path: "folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!170",
path: "response.data.folders[0].id",
element: "file",
overwrite: "rename"
}).then(
function (response) {
document.getElementById("info").innerText =
"File uploaded.";
},
function (responseFailed) {
document.getElementById("info").innerText =
"Error uploading file: " + responseFailed.error.message;
}
);
},
function (responseFailed) {
document.getElementById("info").innerText =
"Error signing in: " + responseFailed.error.message;
}
);
}
</script>
应用设置中的Redirect_URL也与上面提到的相同。我还创建了几个地方提到的callback.html,并用
替换了我的redirect_url redirect_uri: "http://apidomain.com/onedriveapi/callback.html",
页面中的以及https://account.live.com/developers/applications/apisettings的appsettings。
我还想保存收到的令牌和上传到我的db中的文件的位置。任何人帮助解决这个问题,因为我在过去几天里一直在努力解决这个问题。
由于
答案 0 :(得分:0)
FYI。这是html页面的截图。
<html>
<head>
<script src="http://js.live.net/v5.0/wl.js" type="text/javascript"></script>
<script type="text/javascript">
WL.init({
client_id: "################",
redirect_uri: "http://yashlocal.com/skydrive/response",
scope: ["wl.signin", "wl.skydrive", "wl.skydrive_update"],
response_type: "token"
});
function uploadFile() {
WL.login({
scope: "wl.signin"
}).then(
function (response) {
alert(response);
WL.upload({
//path: "folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!170",
path: "response.data.folders[0].id",
element: "file",
overwrite: "rename"
}).then(
function (response) {
document.getElementById("info").innerText =
"File uploaded.";
},
function (responseFailed) {
document.getElementById("info").innerText =
"Error uploading file: " + responseFailed.error.message;
}
);
},
function (responseFailed) {
document.getElementById("info").innerText =
"Error signing in: " + responseFailed.error.message;
}
);
}
</script>
</head>
<body>
<button onclick="uploadFile()">Save file</button>
<label id="info"></label>
</body>
</html>