Google Drive api scope and file access (drive vs drive.files)
Asked Answered
M

3

30

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.

Mailbox answered 14/3, 2014 at 10:53 Comment(0)
V
34

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

Vaud answered 16/5, 2014 at 13:34 Comment(8)
how do i explicitly share a doc with an app ?Benefice
@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 developers.google.com/drive/web/enable-sdk developers.google.com/drive/web/integrate-openVaud
I realized you can do this at OAuth login time with the scope googleapis.com/auth/drive.install, which asks the user directly on the OAuth page if the app can be installed.Vaud
@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'Struthious
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.Fishbein
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?Epigastrium
@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.Vaud
To share a doc with the app, you can prompt the user to pick the doc in the app via google.picker (developers.google.com/picker).Td
T
16

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.

Thithia answered 30/9, 2019 at 20:50 Comment(8)
you saved my lifeFuentes
Thank you!! I did not realize you had to set the app id.Celt
I figured this out from a tutorial (finally), and if I'd read your comment it would have saved me hours.Vaud
Is there any info on how to set appId without using the google file picker? Trying something in flutter and can't find any info in the google api docs at allGrog
stackoverflow.com/a/40638063 for how to find your appId. PickerBuilder.setAppId(string) to do so in the Browser API.Soniasonic
That link doesn't include any information about the AppID anymore, I had to find the working information in the Internet Archive snapshot.Paunchy
Does it work for a whole folder? My app just needs to save the path to a folder for subsequent upload of files thereFirstnighter
Not sure if there's an update on Picker API, but I've tried it few months back and it doesn't give access to files inside the folder. Today, it gives permission to subfolder and files. I'm using firebase auto-generated client and API key for the Picker API though.Pashalik
H
0

I was having the same 404 issue using drive.file and was having success with either just drive or a combination of drive.readonly and drive.file.

In my Google Cloud Console, there wasn't an appId listed -- I ended up using the project number as my appId and now drive.file works like a charm and I don't need any other scopes. Thank you Carlos for the answer. Any others with a non-obvious appId should try setting appId = {project number} as well.

Houlihan answered 2/8, 2024 at 16:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.