我试图为Dropbox Javascript Datastores API创建一个同时支持Android和Windows8的Phonegap应用程序,该应用程序利用了此处提供的示例:https://github.com/dropbox/cordova-datastores-example
当我构建并运行Android应用程序时,它在Android平板电脑上完美运行。但当我运行为Windows8创建的应用程序时,会显示一个错误:The app couldn't navigate to ... because of this error: FORBIDFRAMING
。然后什么也没发生。
我一直找不到使用相框的替代品。我想知道,如果有一种方法可以成功运行这个例子的Windows8应用程序,我会在哪里更改这个例子来替换框架。(或者,如果有另一种方式来验证用户登录,这样我就不必使用框架了。(
谢谢。
前提
这是一个破解的解决方案,可能会被移植到针对dropbox js:的适当的Pull Request
准备工作:
- 从这里下载dropbox-js客户端,并将其放入项目的
js
文件夹中 - 确保它列在您的"解决方案资源管理器"中。如果不是,右键单击文件夹,然后通过"添加->现有项目…"添加
- 将
dropbox.js
添加到您的default.html
中 - 创建一个新文件。我称之为
helpers.js
,并将其添加到您的default.html
中 - 打开
package.appxmanifest
文件并声明一个自定义协议。(声明->从下拉菜单中选择协议->给它一个名称(例如myapp(( - 转到dropbox应用程序控制台并注册一个新的应用程序
- 向注册的应用程序添加重定向URI:
myapp://dropbox
。请注意,myapp
引用了自定义协议
步骤#1:添加助手
将以下内容添加到helpers.js
中: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:将自定义AuthDriver添加到dropbox js
打开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:使用dropbox
在helpers.js中,你会发现一个名为sync
的函数,我用它来
- 检查用户是否已通过身份验证。如果情况并非如此,我们将把他重定向到dropbox
- 下载用户的联系人数据并将其登录到控制台
您基本上只需要使用MyHelpers.dropbox.getClient()
并与生成的客户端进行交互。它将返回dropbox客户端的正确实例
词尾词
希望能有所帮助!您可以在此处找到客户端的可用方法:http://coffeedoc.info/github/dropbox/dropbox-js/master/classes/Dropbox/Client.html#readFile-实例
来源https://github.com/apache/cordova-plugin-inappbrowser/blob/master/doc/index.md,看起来InAppBrowser插件(Dropbox Cordova auth驱动程序使用的插件(实际上并不支持Windows。