相关疑难解决方法(0)

列出Drive中的所有文件

我想使用Google Drive API for Android列出用户云端硬盘的Root文件夹中的所有文件.

我尝试过的:

  1. 使用SCOPE_FILElistChildren:

    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只列出由应用程序,并不是所有的文件被创建的文件.

  1. 使用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)

android google-drive-android-api

5
推荐指数
1
解决办法
2898
查看次数

标签 统计

android ×1

google-drive-android-api ×1