问题
I have attempted to create a Phonegap app supporting both Android and Windows8 for the Dropbox Javascript Datastores API that makes use of the example provided here: https://github.com/dropbox/cordova-datastores-example
When I build and run the Android app, it runs perfectly on the Android tablet. But when I run the app created for Windows8, an error is displayed: The app couldn't navigate to ... because of this error: FORBIDFRAMING. And then nothing happens afterwards.
I haven't been able to find an alternative to using a frame. I would like to know, if there is a way to run the Windows8 app successfully of this example, and where I would change the example to replace the frame. (Or, if there is another way to auth a user sign in so that I don't have to use the frame.)
Thanks.
回答1:
Premise
This is a hacky solution which will probably be ported to a proper Pull Request against dropbox-js:
Preparation:
- Download the dropbox-js client from here and put it into project's
jsfolder. - Ensure that it is listed in your "Solution Explorer". If it isn't, right click on the folder and add it via "Add -> Existing Item...".
- Add
dropbox.jsto yourdefault.html. - Create a new file. I called it
helpers.jsand add it to yourdefault.html. - Open your
package.appxmanifestfile and declare a custom protocol. (Declarations -> Select protocol from the drop down -> Give it a name (e.g. myapp)) - Go to the dropbox app console and register a new application.
- Add a Redirect URI to the registered app:
myapp://dropbox. Note thatmyappreferences the custom protocol.
Step #1: Add helpers
Add the following content to the helpers.js:
http://pastebin.com/qpZbv7YG
Step #2: Add support for the protocol handler
As we added the custom protocol to our app and the redirect uri to dropbox, we need to handle
the call from dropbox. your 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 */
}
})
Step #3: Add a custom AuthDriver to dropbox-js
Open dropbox.js and find the line:
Dropbox.AuthDriver.Cordova = (function (_super) {
Paste the following code just above that line:
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);
Please note that there is again a reference to our custom protocol.
Step #4: Use dropbox
In the helpers.js you will find a function called sync which I use to
- check if the user is already authenticated. If that is not yet the case, we will redirect him to dropbox.
- download the user's contact data and log it into the console.
You basically just have to use MyHelpers.dropbox.getClient() and interact with the resulting client. It will return a proper instance of the dropbox client
Final words
Hope that helps! You can find available methods of the client here: http://coffeedoc.info/github/dropbox/dropbox-js/master/classes/Dropbox/Client.html#readFile-instance
回答2:
From https://github.com/apache/cordova-plugin-inappbrowser/blob/master/doc/index.md, it looks like Windows isn't actually supported by the InAppBrowser plugin (which is what is used by the Dropbox Cordova auth driver).
来源:https://stackoverflow.com/questions/24274286/dropbox-javascript-datastores-api-example-in-phonegap-provides-error-forbidframi