0

我正在使用 Skydrive 文件选择器 javascript api 将文件上传到 Skydrive。但是只要我点击上传按钮......它会打开登录窗口并立即关闭。错误日志显示 WL.login :弹出窗口在未获得任何同意的情况下关闭。

我已经在本地域上托管了我的网络应用程序:apidomain 并将我的文件发布到 IIS @ Default Web Site/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 中。

我还想保存收到的令牌和上传到我的数据库的文件的位置。请任何人帮助解决这个问题,因为我最近几天一直在努力解决这个问题。

谢谢

4

1 回答 1

0

供参考。这是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>
于 2015-01-19T11:02:55.590 回答