28

I have created two refresh tokens for me: one for

SCOPE = 'https://www.googleapis.com/auth/drive'

and another

SCOPE = 'https://www.googleapis.com/auth/drive.file'

I'm trying to get information about files (using get method) Some files I can get when using SCOPE drive.files, and some only when using wider scope drive

But I can not figure out what is the reason for that? Files are located in different folders but have one shared root folder.

WHITECOLOR
  • 24,996
  • 37
  • 121
  • 181

2 Answers2

30

The difference is that 'drive.file' only gives you permission to files that your app has created or the user has explicitly shared with your app, whereas 'drive' gives your app permission to see the all the files in the user's drive.

See

https://developers.google.com/drive/web/scopes

jpolitz
  • 629
  • 1
  • 8
  • 8
  • 21
    how do i explicitly share a doc with an app ? – David Chan Nov 06 '14 at 17:10
  • 1
    @DavidChan I don't know how to do it programmatically. If a user installs your Google Drive App, which is a bit more of a process than just using the OAuth APIs, they can do "Open With..." from the Drive page and select your app. The relevant docs are at https://developers.google.com/drive/web/enable-sdk https://developers.google.com/drive/web/integrate-open – jpolitz Nov 14 '14 at 02:18
  • I realized you can do this at OAuth login time with the scope https://www.googleapis.com/auth/drive.install, which asks the user directly on the OAuth page if the app can be installed. – jpolitz Feb 25 '15 at 22:02
  • @DavidChan create credentials for a service account key which will give you a file in which an email address is, share your google drive file/spreadsheet/whatever with that email address like it was another human. This works for 'drive', however, I am struggling to make it work with 'drive.file' – janjackson Jul 28 '18 at 12:06
  • 1
    Wait wait wait, I have all of the files my clients use owned by one central Google Drive account. Is it possible to give my app full permissions on a folder in Google Drive and allow it to open all of my files? That would be perfect. – NobleUplift Jun 27 '19 at 22:05
  • So If a folder is created using the app, and the user later adds some files in there not created from the app, can the app still access them with the `auth/drive.file` scope? – Max Carroll Sep 23 '19 at 14:39
  • 1
    @MaxCarroll my understanding is no, the app would not be able to access those files. It has to be specific actions to bless the file with the right properties, like: creating a file with "New... -> Choose the app" or opening it with the right-click menu and choosing the app, or having the app create the file with a direct request. – jpolitz Sep 24 '19 at 18:02
  • 3
    To share a doc with the app, you can prompt the user to pick the doc in the app via google.picker (https://developers.google.com/picker). – user2191332 Mar 08 '20 at 00:00
12

You should really look into using drive.file, that is where they are trying to push users. I was just fighting with this myself and found that if you use the drive.file scope, you can then subsequently open the file that is chosen using the API for the file type, but only if you set the correct AppID.

See here: https://developers.google.com/picker/docs/#gdata

This allows you to get past the 404 error that you get if you don't set the AppID.

Carlos Mostek
  • 131
  • 1
  • 4