Premise
这是一个 hacky 解决方案,可能会被移植到针对 dropbox-js 的正确 Pull 请求中:
准备:
- 从以下位置下载 dropbox-js 客户端here http://cdnjs.cloudflare.com/ajax/libs/dropbox.js/0.10.2/dropbox.js并将其放入项目中
js
folder.
- 确保它列在“解决方案资源管理器”中。如果不是,请右键单击该文件夹并通过“添加 -> 现有项目...”添加它。
- Add
dropbox.js
给你的default.html
.
- 创建一个新文件。我叫它
helpers.js
并将其添加到您的default.html
.
- 打开你的
package.appxmanifest
文件并声明自定义协议。 (声明 -> 从下拉菜单中选择协议 -> 为其命名(例如 myapp))
- 转到保管箱应用程序控制台 https://www.dropbox.com/developers/apps并注册一个新的应用程序。
- 将重定向 URI 添加到已注册的应用程序:
myapp://dropbox
。注意myapp
引用自定义协议。
步骤#1:添加助手
添加以下内容到helpers.js
:
http://pastebin.com/qpZbv7YG http://pastebin.com/qpZbv7YG
步骤#2:添加对协议处理程序的支持
当我们将自定义协议添加到我们的应用程序并将重定向 uri 添加到 dropbox 时,我们需要处理
来自 Dropbox 的呼叫。你的default.js
app.addEventListener("activated", function (args) {
if (args.detail.kind === activation.ActivationKind.protocol) {
// the application has been called via the custom protocol
var requestUri = args.detail.uri.rawUri
, params = Dropbox.Util.Oauth.queryParamsFromUrl(requestUri)
AppHelpers.dropbox.setParams(params)
} else if (args.detail.kind === activation.ActivationKind.launch) {
/* you should have this alread in place */
}
})
步骤#3:向 dropbox-js 添加自定义 AuthDriver
打开 dropbox.js 并找到以下行:
Dropbox.AuthDriver.Cordova = (function (_super) {
将以下代码粘贴到该行上方:
Dropbox.AuthDriver.WinRT = (function (_super) {
__extends(WinRT, _super);
function WinRT(options) {
WinRT.__super__.constructor.call(this, options);
}
WinRT.prototype.url = function () {
return 'myapp://dropbox';
};
WinRT.prototype.doAuthorize = function (authUrl, stateParam, client, callback) {
var authHost, browser, onEvent, promptPageLoaded, removed,
_this = this;
var uri = new Windows.Foundation.Uri(authUrl);
Windows.System.Launcher.launchUriAsync(uri)
};
return WinRT;
})(Dropbox.AuthDriver.BrowserBase);
请注意,这里再次引用了我们的自定义协议。
步骤#4:使用保管箱
在 helpers.js 中你会发现一个名为sync
我用过
- 检查用户是否已经通过身份验证。如果情况还不是这样,我们将把他重定向到保管箱。
- 下载用户的联系数据并将其登录到控制台。
你基本上只需要使用MyHelpers.dropbox.getClient()
并与最终的客户端进行交互。它将返回一个正确的实例保管箱客户端 https://github.com/dropbox/dropbox-js/blob/stable/guides/getting_started.md
最后的话
希望有帮助!
您可以在这里找到客户端可用的方法:http://coffeedoc.info/github/dropbox/dropbox-js/master/classes/Dropbox/Client.html#readFile-instance http://coffeedoc.info/github/dropbox/dropbox-js/master/classes/Dropbox/Client.html#readFile-instance