微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android-Cordova移动应用程序和Dropbox API v2

是否有人在Cordova移动应用程序中使用了DropBox API v2?甚至是移动应用期?有API v1&的教程.科尔多瓦:
http://ourcodeworld.com/articles/read/149/how-to-use-dropbox-in-a-cordova-application
但是DropBox已经或正在弃用它.

我有一个Github项目,它是一个基本的Cordova项目(版本6.5.0),并且包含DropBox API v2.我可以使项目进入授权屏幕,但我认为我的问题是重定向URI.

我正在使用:

>科尔多瓦6.5.0
>在Android上进行测试
> DropBox API v2:https://github.com/dropbox/dropbox-sdk-js
>授权示例:https://github.com/dropbox/dropbox-sdk-js/blob/master/examples/auth/index.html

但是再次,我已经将所有内容都放入了Github仓库中:
https://github.com/ModusPwnens1337/dropboxTest

我相信重定向URI是问题所在,您可以在index.html的第128行找到它:

var authUrl = dbx.getAuthenticationUrl('https://www.dropBox.com/oauth2/authorize?response_type=token&client_id=8nvbrxvlg96tx1k&redirect_uri=helloworld://localhost/callback');

请让我知道是否有人获得授权或重定向到移动应用的授权.

先感谢您!

解决方法:

好吧,我已经弄清楚了!
我在该项目中遇到三个问题:

>我的重定向URI错误,应该只是以下内容

var authUrl = dbx.getAuthenticationUrl(‘helloworld:// localhost / callback’);
>我没有正确设置自定义URL方案,幸运的是,有一个漂亮的小插件要使用:https://github.com/EddyVerbruggen/Custom-URL-scheme.这是我在CLI中运行的安装插件方法:cordova plugin add cordova-plugin-customurlscheme –variable URL_SCHEME =你好,世界
>添加插件并阅读说明后,您将看到需要添加一个函数来处理回调访问令牌,如下所示:

function handleOpenURL(url) {
    console.log("handleOpenURL: " + url);
    showPageSection('authed-section');
    // Create an instance of DropBox with the access token and use it to
    // fetch and render the files in the users root directory.
    var dbx = new DropBox({ accesstoken: getAccesstokenFromUrl2(url) });
    dbx.filesListFolder({path: ''})
        .then(function(response) {
            renderItems(response.entries);
        })
        .catch(function(error) {
            console.error(error);
        });
}

并且还必须编辑getAccesstokenFromCustomUrl才能适用于新的回调:

function getAccesstokenFromUrl2(url) {
    url = url.split('#')[1];
    console.log('getAccesstokenFromUrl2: ' + utils.parseQueryString(url).access_token);
    return utils.parseQueryString(url).access_token;
}

请注意,不要忘记重定向uri需要在应用程序控制台上的应用程序页面上预先注册https://www.dropbox.com/developers/apps

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐