DriveResource.listParents not working

I am developing an Android application where I need to get the list of parents of a file taken from Google Drive.

I get DriveId correctly using Drive.DriveApi.newOpenFileActivityBuilder (), but when I use DriveResource.listParents, I get an empty list, even if the resource has a parent element.

I use the same GoogleApiClient for Drive.DriveApi.newOpenFileActivityBuilder () and DriveResource.listParents, so I don't think this is a scope problem.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (requestCode == Constants.REQUEST_CODE_GOOGLE_DRIVE_FILE_PICKER) {
      if (resultCode == RESULT_OK) {
         mSelectedFileDriveId = (DriveId)    data.getParcelableExtra(OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
      } else {
         setResult(Constants.RESULT_CODE_KO);
         finish();
      }
   }
}

...

private ResultCallback<MetadataBufferResult> metadataBufferCallback = new ResultCallback<MetadataBufferResult>() {
   @Override
   public void onResult(MetadataBufferResult result) {
      if (!result.getStatus().isSuccess()) {
         SDKUtils.showMessage(thisActivity, "Impossible salvare l'ultima posizione aperta in Google Drive");
          return;
      }
      MetadataBuffer metadataBuffer = result.getMetadataBuffer();
      // HERE I OBTAIN AN EMPTY OBJECT
   }
};

...

mGoogleApiClient = new GoogleApiClient.Builder(this)
              .setAccountName(driveAccontName)
              .addApi(Drive.API)
              .addScope(Drive.SCOPE_FILE)
              .addConnectionCallbacks(this)
              .addOnConnectionFailedListener(this).build();

...

DriveFile driveFile = Drive.DriveApi.getFile(getGoogleApiClient(), mSelectedFileDriveId);
driveFile.listParents(GoogleApiClient apiClient).setResultCallback(metadataBufferCallback);

Are there any suggestions? Thank!

+1
source share
1 answer

, so I don’t think this is a problem with the area.

This is exactly what the scope problem is !!!

API Android Google drive.file drive.appfolder.

, . Drive.DriveApi.newOpenFileActivityBuilder() , , Select.

, -

    /root
      |
      +---books
          +---c++
              +---programming_gems.pdf
              +---c++_notes.docs

, Drive.DriveApi.newOpenFileActivityBuilder(), program_gems.pdf. PDF . . , ++ . ? ++; . ; .

++, Drive.DriveApi.newOpenFileActivityBuilder(). , program_gems.pdf, .

; ++. ? - program_gems.pdf. , , ++ _ notes.docs.

, .

P.S.

  • , , mime. . , ,

    if (openFolder) {
        mime_type = new String[]{DriveFolder.MIME_TYPE};
    } else {
        mime_type = new String[]{};
    }
    
    IntentSender intentSender = Drive.DriveApi
            .newOpenFileActivityBuilder()
            .setMimeType(mime_type)
            .build(getGoogleApiClient());
    
  • , API- REST Google - - fooobar.com/questions/1538962/...

0

Source: https://habr.com/ru/post/1538956/


All Articles