问题描述
我在Cordova / PhoneGap中编写一个应用程序,尝试使用Dropbox.js从Dropbox提取文件。 Cordova版本为3.0.1,Dropbox.js版本为0.10.0。我的Javascript在桌面浏览器上工作得很好:
var client = new Dropbox.Client({key:& my key>,secret:< my secret>});
client.authenticate(function(error,client){
...
但是在Cordova打包的应用程序中,我得到一个错误:你似乎正在使用的应用程序提交了一个错误的请求。
我怀疑问题与在Cordova应用程序中解析到此的重定向网址:
Dropbox.AuthDriver.BrowserBase.currentLocation - > file:///android_asset/www/index.html
file:///无法正常使用Dropbox API,即使我将它们添加到Dropbox API控制台中的OAuth重定向URI。
Cordova应用程序如果我知道之前的uid和令牌:
var client = new Dropbox.Client({
key: < my key,
secret:< my secret>,
token:< token>,
uid:< uid> );
client.authenticate(function(error,client){
...
这样我就可以读取我的dropbox文件了。问题是,令牌不会永远持续,我想从我的应用程序本身获得一个新的。
根据,此问题应该已经在早期版本的dropbox.js(0.9.2)中解决。但我还是遇到了。我不知道我应该使用API有点不同,但我不知道如何。
Dropbox.js在此提交中添加了一个redirectUrl选项我只是不知道我应该把什么放在我的Cordova应用程序。文件:///android_asset/www/index.html将无法使用,因为Dropbox API不允许文件网址。
Simon McDonald对可能有所帮助。但这意味着我必须有一个外部服务器托管页面和dropbox.js登录功能。或者我可以使用主要的dropbox web登录页面吗?
dropbox.js 0.10.1有一些修复Cordova。 / p>
我们刚刚设置了一个网页,您可以在嵌入式WebView中使用OAuth 2重定向网址,但file://无效。
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?
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
这篇关于Cordova / PhoneGap中的Dropbox.js身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!