2016-04-07 96 views
0

几个星期,试图处理如何连接到Dropbox和我自己的应用程序。我使用dropbokse创建了一个应用程序,并连接到他。当记录出现​​时,我被要求确认使用文件的可能性的窗口。我点击允许(在dropbokse开发用户的附件中增加1),但是这个盒子不会消失,不会关闭,也不会去授权。已经在这里下载了一个例子:https://github.com/donovan-graham/cordova_oauth。情况完全一样。但在这种情况下清楚地表明,授权不是错误,但只是一切都挂起。 (但是如果以前重置开发用户,那么当它失败时,记录日志仍然会增加1)授权。 Dropbox的。科尔多瓦

回答

1

可能不会直接回答你的问题,但这可能有帮助。

您可以使用Dropbox HTTP API将您的Cordova应用程序与http请求链接起来。在我的应用程序中,我使用这些http请求将其链接到Dropbox,因为目前没有官方的Dropbox JavaScript文档。

为了开始Dropbox身份验证,您应该让用户导航到https://www.dropbox.com/oath2/authorise。这可以通过使用cordova-plugin-inappbrowser在您的应用程序中轻松完成。

例如

var response_type = 'code'; 
var client_id = '<your-dropbox_app_client_id>'; 
var redirect_uri = 'https://www.dropbox.com/1/oauth2/redirect_receiver'; 
var data = 'response_type=' + response_type + '&client_id=' + client_id + '&redirect_uri=' + redirect_uri'; 

var ref = cordova.InAppBrowser.open(
    'https://www.dropbox.com/oauth2/authorize?' + data', 
    '_blank', 
    'location=no,clearcache=yes' 
); 

ref.addEventListener('loadstop', function(event) { 
    // get the response from event.url 
    var code = event.url.substring(redirect_uri.length + 6); 

    var headers = new Headers(); 
    headers.append('Authorization', 'Basic <your basic auth here>'); 
    headers.append('Content-Type', 'application/x-www-form-urlencoded'); 

    var request = `code=${code}&grant_type=authorization_code&redirect_uri=${redirect_uri}`; 
    var observable = http.post('https://api.dropboxapi.com/oauth2/token', request, { headers: headers }); 

    // the data returned will have the access_token that will link Dropbox to your App!! 
}); 

的一些注意事项 这个例子是Angular2内置了科尔多瓦的应用程序中。因此,http模块返回observables。您可以使用jQuery或其他类似的工具轻松执行这些步骤($.ajax)。

我们使用https://www.dropbox.com/1/oauth2/redirect_receiver作为redirect_url,因为它必须是https连接,并且我们的access_token将被发送。您必须确保这个url已经在您的Dropbox-app页面中输入到您允许的重定向网址中!

最后,您的<basic-auth-here>是您的Dropbox应用程序的应用程序密钥和秘密密钥的基本http身份验证。

祝你好运!