2017-07-27 50 views
-1

我想使用新的APIv2將保存的csv文件上傳到Dropbox,但它無法正常工作。我正在使用兩個按鈕。 First Button具有用於驗證的OnClick方法「dropbox」,並且其工作正常。但第二個OnClick方法「上傳」不起作用。我不確定「配置」和參數是什麼。需要你的幫助。這是代碼。Android使用API​​v2將文件上傳到保管箱

public void dropbox(View view) { 
     Auth.startOAuth2Authentication(MainActivity.this, APP_KEY); 

    } 

public void uploadfile(View view){ 
 
     DbxClientV2 client; 
 
     DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder("examples-v2-demo") 
 
       .withHttpRequestor(new OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient())) 
 
       .build(); 
 

 
     client = new DbxClientV2(requestConfig, ACCESS_TOKEN); 
 

 
     try { 
 
      File file = new File(getExternalFilesDir(null), "u1u2u.csv"); 
 
      FileInputStream in = new FileInputStream(file); 
 
      FileMetadata metadata = client.files().uploadBuilder("/u1u2u.csv") 
 
        .uploadAndFinish(in); 
 
     } 
 
     catch(DbxException | IOException e){ 
 

 
     } 
 

 
    }

我嘗試這個代碼,請從Github上的Dropbox文件,但是當我運行這個它讓我2個錯誤。

錯誤:(1503,93)錯誤:無法訪問okhttp3.OkHttpClient OkHttpClient 類文件未找到 錯誤:執行失敗的任務 ':應用程序:compileDebugJavaWithJavac'。

Compilation failed; see the compiler error output for details.

+0

什麼是錯誤?你可以發佈日誌嗎? – dhiku

回答

0

試試這個。您必須添加OkHttp的依賴關係。

StandardHttpRequestor requestor = new StandardHttpRequestor(config); 
DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder(clientUserAgentId) 
    .withHttpRequestor(requestor) 
    .build(); 
new DbxClientV2(requestConfig, auth.getAccessToken(), auth.getHost()); 
+0

謝謝。錯誤不再發生,但我仍然不能上傳文件。 – Paladin83

+0

CloudRail爲Dropbox,Box,Google Drive(等等)實現提供了一個簡單易用的方法https://cloudrail.com/integrations/interfaces/CloudStorage – Paladin83

相關問題