Skip to content Skip to sidebar Skip to footer

Drive API For Android Unable To Access The File Created By Same App

I am writing an app where one user will write a file through this app and share it with other users using a link. Other users will read the file using same mobile app. I am using '

Solution 1:

I had a similar issue but not with an android app but a JavaScript app (should not matter IMO) and I wanted to access a shared file not a folder. However, I guess my workaround could help you as well.

The first approach is using the full auth scope (see https://developers.google.com/drive/web/scopes)

https://www.googleapis.com/auth/drive

But that is not really desired since you should request as few rights as possible from your users. My work-around was therefore as follows:

  1. I used the Drive UI Integration
    • Goto https://console.developers.google.com/apis/api/drive/drive_sdk
    • select the "Drive UI Integration" tab
    • fill out the form, I have used the following:
      • "Application Name"
      • The mandatory "Application icons"
      • activated "Automatically show OAuth 2.0 consent screen when users open my application from Google Drive" and entered my "CLIENT ID"
      • used a dummy url for "Open Url" (e.g., http://example.com)
      • provided a default file extension (this way your app will be suggested afterwards when the user opens a file)
    • save your changes
  2. Add the following scope to your app

https://www.googleapis.com/auth/drive.install

  1. The users will install your app when approving the requested rights
  2. Request your users to open the shared files with your "dummy" app in the google drive folder, which will grant your app access to the file (as stated here: https://developers.google.com/drive/web/scopes -- https://www.googleapis.com/auth/drive.file = Per-file access to files created or opened by the app) -- notice that the user will see an error message when opening your dummy app. You should probably implement an open url with something saying "thank's for granting access to the file xYZ".
  3. your app is now able to access the shared file.

I know, it is not very user-friendly but it works (at least now, might be that this is not intentional) If you know a way to automatically open a file with an app by invoking some URL, then please let me know. (yet, that would kind of be a security issue in the Google API, so I guess it is not possible).

Since it is somewhat cumbersome, I will propose the following two options to the user (so she/he can decide on her/his own):

  1. Give the app full access and don't be concerned about this issue at the cost of privacy (I am certainly not evil and would not do anything with the files, but might be that someone can hack my app and get access to the accounts and then... well, then the user would have wished to give my app less rights.)
  2. Give only install rights in addition but with the pain to open every single file which the app needs access to. In my case this is relatively rare so it should not really bother the user.

I hope that helps.


Solution 2:

Assuming this as a limitation of Drive API for Android, I am switching to Drive REST API. I found the functionality I was looking for in the Drive REST API i.e. incremental updates to the file and resumable downloads. Just that I need to manage some of the things on my own.

In that way, Drive REST API is complete and it can provide all the functionalities whereas Drive API for Android is constrained with lot of limitations. With no answers to my questions, I am assuming that it is not possible to share files with other users through Google Drive using Drive API for Android.


Solution 3:

You can add full permissive drive scope - https://www.googleapis.com/auth/drive

request scope using -

.requestScopes(new Scope("https://www.googleapis.com/auth/drive"))

instead of

.resuestScopes(Drive.SCOPE_FILE)

Post a Comment for "Drive API For Android Unable To Access The File Created By Same App"