5

I'm writing an app in Cordova/PhoneGap which tries to fetch a file from Dropbox using Dropbox.js. Cordova version is 3.0.1 and Dropbox.js version is 0.10.0. My Javascript works just fine on a desktop browser with this:

var client = new Dropbox.Client({ key: "<my key>", secret: "<my secret>"} );
client.authenticate(function(error, client) {
...

But in the Cordova-packaged app I get an error: "It seems the app you were using submitted a bad request".

I suspect the problem has to do with the redirect-url which resolves to this in the Cordova app:

Dropbox.AuthDriver.BrowserBase.currentLocation()
-> file:///android_asset/www/index.html

Urls starting with file:/// will not work properly with Dropbox API even if I add them to OAuth redirect URIs in Dropbox API console.

The Cordova app does work fine if I know the uid and token before:

var client = new Dropbox.Client({
    key: "<my key",
    secret: "<my secret>",
    token: "<token>",
    uid: "<uid>"
});
client.authenticate(function(error, client) {
...

This way I can read my dropbox files just fine. Problem is that the token doesn't last forever and I 'd like to get a new one from my app itself.

According to this discussion, this issue should already have been resolved in an earlier version of dropbox.js (0.9.2). But I still run into it. I wonder if I should use the API a bit differently, but I don't know how.

Dropbox.js has added a redirectUrl option in this commit I just don't know exactly what should I put there in my Cordova app. The file:///android_asset/www/index.html will not work because Dropbox API does not allow file urls.

Simon McDonald's answer to this question might help. But that means I have to have an external server-hosted page with the dropbox.js login functionality. Or could I use the main dropbox web login page instead?

Community
  • 1
  • 1
auramo
  • 13,167
  • 13
  • 66
  • 88

1 Answers1

5

dropbox.js 0.10.1 has some fixes for Cordova.

We have just set up a page that you can use as the OAuth 2 redirect URL in embedded WebViews, when file:// doesn't work.

https://www.dropbox.com/1/oauth2/redirect_receiver

pwnall
  • 6,634
  • 2
  • 23
  • 30
  • Great! I'll test the master version and if it doesn't work, at least I don't have to host and create the interactive https login page myself because you have created one already. – auramo Aug 05 '13 at 10:07
  • The master version seems to have the same problem: https://github.com/dropbox/dropbox-js/issues/106#issuecomment-22203159 – auramo Aug 06 '13 at 20:04
  • Now there's a new version which works further: https://github.com/dropbox/dropbox-js/issues/106#issuecomment-22726393 – auramo Aug 15 '13 at 20:09
  • Got it working with the version mentioned in my previous comment: https://github.com/dropbox/dropbox-js/issues/106#issuecomment-22827628. The secret was to add the InAppBrowser plugin with this command: cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git – auramo Aug 18 '13 at 09:47