【问题标题】:unable to query the files "shared with me" from google drive using Google drive api android无法使用 Google Drive api android 从 Google Drive 查询“与我共享”的文件
【发布时间】:2014-11-18 10:39:50
【问题描述】:
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());
           }
        };
 }

我无法使用上述代码查询已与我共享的文件和文件夹。每当我尝试查询 sharedWithMe() 时,我都会得到 mResultAdapter 数组计数“0”。请帮我解决这个问题。

【问题讨论】:

    标签: android google-api google-drive-api google-drive-android-api


    【解决方案1】:

    Android API 使用 Drive.File 范围,这意味着您的应用可以访问由您的应用创建或显式打开的文件。其他文件不会显示在搜索结果中。

    【讨论】:

    • Cheryl Simon,我必须做什么才能使用 android api 从 Google 驱动器中列出与我共享的文件
    【解决方案2】:

    Cheryl 是对的,你必须使用 Google APIs Java Client,这里也说过:

    注意:Google Drive Android API 目前仅支持 drive.file 和 drive.appfolder 授权范围。如果您的应用程序需要 Drive Android API 中尚不可用的其他权限或功能,您必须使用 Google APIs Java 客户端。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多