I have some files in my Google Drive that others have shared with me and I would like to be able to query them. Unfortunately the MetadataBuffer' result count is 0
This is the code:
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(com.google.android.gms.drive.Drive.API)
.addScope(com.google.android.gms.drive.Drive.SCOPE_FILE).addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).build();
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
public void onConnected(Bundle arg0) {
Query query = new Query.Builder().addFilter(Filters.sharedWithMe()).build();
Drive.DriveApi.query(mGoogleApiClient, query).setResultCallback(metadataCallback);
}
private ResultCallback<DriveApi.MetadataBufferResult> metadataCallback =
new ResultCallback<DriveApi.MetadataBufferResult>() {
@Override
public void onResult(DriveApi.MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
Log.d(TAG, "Problem while retrieving results");
return;
}
MetadataBuffer buffer = result.getMetadataBuffer();
if(buffer != null) {
int cnt = buffer.getCount();
Log.d(TAG, "BUFFER COUNT: " + cnt);
for(int i = 0; i < cnt; i++) {
Metadata meta = buffer.get(i);
Log.d(TAG, meta.getTitle());
}
buffer.close();
}
}
};
....................
I am using the new Google Drive and I also tried moving some shared files from the Incoming Folder into the My Drive root. Still nothing. I would appreciate any help and suggestions.
As said also on unable to query the files "shared with me" from google drive using Google drive api android , at the moment drive apis let you access only data in drive made by your app.
you can verify by yourself by changing Query query = new Query.Builder().addFilter(Filters.sharedWithMe()).build(); in Query query = new Query.Builder().build();
and you see only one folder, named "App Data"
to access other files you need to use drive java api, as told in https://developers.google.com/drive/android/auth#connecting_and_authorizing_the_google_drive_android_api
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.
来源:https://stackoverflow.com/questions/26929154/unable-to-get-the-shared-with-me-files-with-the-google-drive-api-using-filters-s