我正在 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:/// 开头的 URL 添加到 Dropbox API 控制台中的 OAuth 重定向 URI,也无法在 Dropbox API 中正常工作。
如果我之前知道 uid 和 token,Cordova 应用程序确实可以正常工作:
var client = new Dropbox.Client({
key: "<my key",
secret: "<my secret>",
token: "<token>",
uid: "<uid>"
});
client.authenticate(function(error, client) {
...
这样我就可以很好地读取我的保管箱文件。问题是令牌不会永远持续,我想从我的应用程序本身获取一个新令牌。
根据这次讨论 https://github.com/dropbox/dropbox-js/issues/49,这个问题应该已经在早期版本的 dropbox.js (0.9.2) 中得到解决。但我还是遇到了。我想知道是否应该以不同的方式使用 API,但我不知道如何做。
Dropbox.js 添加了一个redirectUrl 选项在这次提交中 https://github.com/dropbox/dropbox-js/commit/a34f8571e23a67fbd75e582186c28a4bb1a31f72我只是不知道应该在 Cordova 应用程序中放置什么。 file:///android_asset/www/index.html 将不起作用,因为 Dropbox API 不允许文件 URL。
西蒙·麦克唐纳的回答这个问题 https://stackoverflow.com/questions/12940955/phonegap-open-external-page-and-then-go-back-to-app可能有帮助。但这意味着我必须拥有一个具有 dropbox.js 登录功能的外部服务器托管页面。或者我可以使用主要的 Dropbox Web 登录页面吗?