2015-11-10 97 views
0

我試圖從谷歌驅動器應用程序文件夾下載文件,併爲此我需要驅動器ID(我認爲是這樣),但與我使用的驅動器ID代碼如下,我不斷收到文件/文件夾找不到錯誤。無法檢索文件上傳到谷歌驅動器應用程序文件夾的驅動器號碼

Drive.DriveApi.getAppFolder(mGoogleApiClientDrive) 
      .listChildren(mGoogleApiClientDrive) 
      .setResultCallback(new ResultCallback<DriveApi.MetadataBufferResult>() { 
       @Override 
       public void onResult(DriveApi.MetadataBufferResult result) { 
        if (!result.getStatus().isSuccess()) { 
         Toast.makeText(GoogleSignIn.this, "Unable to get any result", Toast.LENGTH_SHORT).show(); 
        } 

        MetadataBuffer mdb = result.getMetadataBuffer(); 
        String ID = mdb.get(0).getDriveId().encodeToString(); 

        // Method for downloading data from google drive 
        downloadContent(ID); 
       } 
      }); 

當然,我試圖獲取驅動器ID時做錯了什麼。嘗試getResourceID()我的運氣也一樣,但同樣的錯誤。

回答

0

您是否仔細檢查了您的範圍?該代碼應該是這樣的:

GoogleApiClient mGAC = new GoogleApiClient.Builder(act) 
    .addApi(Drive.API) 
    .addScope(Drive.SCOPE_FILE) 
    .addScope(Drive.SCOPE_APPFOLDER) 
    .addConnectionCallbacks(... ) 
    .addOnConnectionFailedListener(...) 
    .setAccountName(email) 
    .build(); 

好運

相關問題