DriveResource.listParents does not work

后端 未结 1 1082
星月不相逢
星月不相逢 2021-01-24 07:48

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

I correctly obtain the DriveId using Drive.DriveAp

相关标签:
1条回答
  • 2021-01-24 08:18

    so i do not think that is a scope problem.

    It's exactly that - Scope problem !!!

    Google Drive Android API provides only drive.file and drive.appfolder scope.

    File scope means access only to those files which the user chooses from your application. The Drive.DriveApi.newOpenFileActivityBuilder() dialog will let the user browse through the whole drive but your application will be granted access to only those file or folder which the user specifically Select's.

    Suppose you have following folder structure on your drive -

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

    Now using Drive.DriveApi.newOpenFileActivityBuilder() you pick up programming_gems.pdf. Your app has now obtained access to that pdf. You can retrieve the file and its metadata. But your app won't be able to obtain access to its parent folder, c++ in this case. Why? because the user has not yet given access to c++ folder; only a specific file within that folder. This makes sense also; otherwise you can retrieve any file from that folder leaving your user worried.

    Pick up c++ folder using the same Drive.DriveApi.newOpenFileActivityBuilder(). Now if your app tries to retrieve the parent folder of programming_gems.pdf, it is granted access.

    Try one more thing now; try to list the contents of c++ folder itself. What wil be returned to your app? - only programming_gems.pdf. Why, because the user has not granted access to the other file, c++_notes.docs.

    I hope am clear.

    P.S.

    1. By the way, to select between picking up files or folder, you have to set the mime type. See the following code for e.g.,

      if (openFolder) {
          mime_type = new String[]{DriveFolder.MIME_TYPE};
      } else {
          mime_type = new String[]{};
      }
      
      IntentSender intentSender = Drive.DriveApi
              .newOpenFileActivityBuilder()
              .setMimeType(mime_type)
              .build(getGoogleApiClient());
      
    2. If this scheme of scopes don't match your requirements you can alternatively use the Google Drive REST APIs - Read on - https://stackoverflow.com/a/25871516/1363471

    0 讨论(0)
提交回复
热议问题