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

喜夏-厌秋 提交于 2019-12-08 03:59:47

问题


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'. please help me to solve this issue.


回答1:


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. Other files will not show up in search results.




回答2:


Cheryl is right, you have to use Google APIs Java Client as said also here:

Note: The Google Drive Android API currently only supports drive.file and drive.appfolder authorization scopes. If your application requires additional permissions or features not yet available in the Drive Android API, you must use the Google APIs Java Client.

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



来源:https://stackoverflow.com/questions/26992251/unable-to-query-the-files-shared-with-me-from-google-drive-using-google-drive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!