gpt4 book ai didi

android - 列出云端硬盘中的所有文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:08:19 29 4
gpt4 key购买 nike

我想使用适用于 Android 的 Google Drive API 列出用户云端硬盘根文件夹中的所有文件。

我尝试过的:

  1. 使用 SCOPE_FILElistChildren:

    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!
}
}

我已经 found 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();

异常失败:

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)

它是打算以这种方式工作,还是我遗漏了什么?

最佳答案

您无法使用 Google Drive API(Android 库)列出所有文件(不是由您的应用创建的文件)。您应该使用 Google Drive REST API。

您尝试使用的范围是 REST API。

这是来自文档页面:

Note: The Android Drive API only works with the https://www.googleapis.com/auth/drive.file scope. This means that only files which a user has opened or created with your application can be matched by a query.

https://developers.google.com/drive/android/queries

关于android - 列出云端硬盘中的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34253889/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com