我想使用Google Drive API for Android列出用户云端硬盘的Root文件夹中的所有文件.
我尝试过的:
使用SCOPE_FILE
和listChildren
:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Run Code Online (Sandbox Code Playgroud)然后列出文件:
Drive.DriveApi.getRootFolder(mGoogleApiClient)
.listChildren(mGoogleApiClient)
.setResultCallback(new ResultCallback<DriveApi.MetadataBufferResult>() {
@Override
public void onResult(DriveApi.MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
Log.v("DKDK", "Request failed");
return;
}
MetadataBuffer metadataBuffer = result.getMetadataBuffer(); // empty!
}
}
Run Code Online (Sandbox Code Playgroud)
我发现是SCOPE_FILE
只列出由应用程序,并不是所有的文件被创建的文件.
使用https://www.googleapis.com/auth/drive
范围
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(new Scope("https://www.googleapis.com/auth/drive"))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Run Code Online (Sandbox Code Playgroud)失败,例外:
com.google.android.gms.drive.auth.c: Authorization failed: Unsupported scope: https://www.googleapis.com/auth/drive
at com.google.android.gms.drive.auth.g.a(SourceFile:86)
at com.google.android.gms.drive.api.e.<init>(SourceFile:230)
at com.google.android.gms.drive.api.a.q.a(SourceFile:71)
at …
Run Code Online (Sandbox Code Playgroud)