【发布时间】:2015-12-13 17:15:20
【问题描述】:
我想使用适用于 Android 的 Google Drive API 列出用户 Drive 根文件夹中的所有文件。
我尝试过的:
-
使用
SCOPE_FILE和listChildren:mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build();
然后列出文件:
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!
}
}
foundSCOPE_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();
异常失败:
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 com.google.android.gms.common.service.f.run(SourceFile:176)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at com.google.android.gms.common.util.a.c.run(SourceFile:17)
at java.lang.Thread.run(Thread.java:856)
它是打算以这种方式工作,还是我遗漏了什么?
【问题讨论】:
标签: android google-drive-android-api