简体   繁体   English

无法使用Google Drive API Android从Google Drive查询“与我共享”的文件

[英]unable to query the files “shared with me” from google drive using Google drive api android

public class QueryFilesSharedWithMeActivity extends BaseDemoActivity {

private ListView mResultsListView;
private ResultsAdapter mResultsAdapter;

@Override
protected void onCreate(Bundle b) {
    super.onCreate(b);
    setContentView(R.layout.activity_listfiles);
    mResultsListView = (ListView) findViewById(R.id.listViewResults);
    mResultsAdapter = new ResultsAdapter(this);
    mResultsListView.setAdapter(mResultsAdapter);
}

/**
 * Clears the result buffer to avoid memory leaks as soon as the activity is no longer
 * visible by the user.
 */
@Override
protected void onStop() {
    super.onStop();
    mResultsAdapter.clear();
}

@Override
public void onConnected(Bundle connectionHint) {
    super.onConnected(connectionHint);
    Query query = new Query.Builder()
            .addFilter(Filters.sharedWithMe())
            .build();
    Drive.DriveApi.query(getGoogleApiClient(), query)
            .setResultCallback(metadataCallback);
    showMessage("Connecting ...");
}

final private ResultCallback<DriveApi.MetadataBufferResult> metadataCallback =
        new ResultCallback<DriveApi.MetadataBufferResult>() {
            @Override
            public void onResult(DriveApi.MetadataBufferResult result) {
                showMessage("onResult ...");
                if (!result.getStatus().isSuccess()) {
                    showMessage("Problem while retrieving results");
                    return;
                }
                mResultsAdapter.clear();
                mResultsAdapter.append(result.getMetadataBuffer());
                showMessage("Count = "+mResultsAdapter.getCount());
           }
        };
 }

I am not able to query the files and folders that already shared with me by using the above code. 我无法使用上面的代码查询与我共享的文件和文件夹。 Whenever i am trying to query sharedWithMe() i am getting the mResultAdapter array count '0'. 每当我尝试查询sharedWithMe()时,我都会得到mResultAdapter数组计数为'0'。 please help me to solve this issue. 请帮助我解决此问题。

The Android API uses Drive.File scope, which means your app has access to files that have been created by, or explicitly opened with your app. Android API使用Drive.File范围,这意味着您的应用程序有权访问由您的应用程序创建或通过应用程序明确打开的文件。 Other files will not show up in search results. 其他文件将不会显示在搜索结果中。

Cheryl is right, you have to use Google APIs Java Client as said also here: Cheryl是对的,您还必须按照以下说明使用Google API Java Client

Note: The Google Drive Android API currently only supports drive.file and drive.appfolder authorization scopes. 注意:Google Drive Android API当前仅支持drive.file和drive.appfolder授权范围。 If your application requires additional permissions or features not yet available in the Drive Android API, you must use the Google APIs Java Client. 如果您的应用程序需要其他权限或云端硬盘Android API中尚不可用的功能,则必须使用Google API Java Client。

source: https://developers.google.com/drive/android/auth#connecting_and_authorizing_the_google_drive_android_api 来源: https//developers.google.com/drive/android/auth#connecting_and_authorizing_the_google_drive_android_api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用Filters.sharedWithMe()与Google云端硬盘Api获得与我共享的文件 - Unable to get the shared with me files with the Google Drive Api using Filters.sharedWithMe() 无法使用新的Drive API检索Google云端硬盘文件和文件夹 - Unable to retrieve Google Drive files and folders using new Drive API 使用 Google Drive Android API 从 Google Drive 下载图像? - Downloading Images from Google Drive using Google Drive Android API? 在Android中使用Google Drive API上传文件 - Uploading files using google drive api in android 流音频文件以在Android中使用Google Drive API从Google Drive播放 - stream audio files to play from google drive using google drive api in android 谷歌驱动器配额使用android api驱动器 - google drive quota using android api for drive 如何使用Google Drive Android API删除Google Drive上的文件 - How to delete a file on google drive using Google Drive Android API 在Android中以编程方式使用Google Drive API将图像上传到Google Drive - Upload image to a google drive using google drive api programatically in android 在 Android Studio 中使用 Google Drive API 从驱动器下载文件以上传到另一个驱动器 - Download file from drive to upload into another drive using Google Drive API in Android Studio 适用于Google云端硬盘的Android API? - Android API for Google Drive?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM