2016-04-07 95 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身份驗證。

祝你好運!