drive.file scope - information - documentation - explanation

289 views
Skip to first unread message

Alan Wells

unread,
May 31, 2019, 8:54:21 AM5/31/19
to Google Apps Script Community
Where is the:

drive.file

scope explained?  Where is the documentation?

Alan Wells

unread,
May 31, 2019, 9:01:56 AM5/31/19
to Google Apps Script Community


View and manage Google Drive files and folders that you have opened or created with this app

Steve Webster

unread,
May 31, 2019, 9:07:35 AM5/31/19
to google-apps-sc...@googlegroups.com
I have also read a design that prompts for Drive files using the Picker will that drive.file scope will avoid the costly security assessment. For example, the app/add-on prompts for a folder or select multiple files via the Picker.

Kind Regards,

Steve Webster
SW gApps, President 
Google Product Expert in: Google Apps Script, Drive, and Docs 
Google Vendor (2012-2013) || Google Apps Developer Blog Guest Blogger 
Add-ons: Text gBlaster and Remove Blank Rows


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/b5cf0d76-915a-4c1a-8381-ec26f75df1f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Gagliano

unread,
May 31, 2019, 10:58:10 AM5/31/19
to Google Apps Script Community
Gents, when a user selects an existing file / folder using the File Picker, does that automatically consider your application as having authorization to use that file under the drive.file scope? Or is there some additional flow that needs to be incorporated?

Alan Wells

unread,
May 31, 2019, 12:59:52 PM5/31/19
to Google Apps Script Community
I was wondering that also.  I'm assuming/hoping that Eric Koleda will address this and other questions in the Totally Unscripted presentation.


On Friday, May 31, 2019 at 10:58:10 AM UTC-4, Robert Gagliano wrote:
Gents, when a user selects an existing file / folder using the File Picker, does that automatically consider your application as having authorization to use that file under the drive.file scope? Or is there some additional flow that needs to be incorporated?

Eric Koleda

unread,
Jun 10, 2019, 9:49:09 AM6/10/19
to Google Apps Script Community
Hi,

No, I didn't address that during the episode, but the answer is yes, as soon as they click the "Select" button at the bottom of the picker the app has access via the drive.file scope.

- Eric

Faustino Rodriguez

unread,
Jun 11, 2019, 11:31:02 AM6/11/19
to Google Apps Script Community
Sorry,
- Do you also mean, access to all the files within the selected folder?

Eric Koleda

unread,
Jun 11, 2019, 4:01:05 PM6/11/19
to google-apps-sc...@googlegroups.com
Sorry, I was just talking about the timing. Unfortunately the drive.file scope doesn't give you access to files within a folder that was picked.

- Eric

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/_W-NKbttfbo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.

Faustino Rodriguez

unread,
Jun 17, 2019, 7:12:52 AM6/17/19
to Google Apps Script Community
Hi @Eric,
Selecting a file with the Picker is not giving the Script access to that file

Please, what I am missing or doing wrong on my side?

We are using the code sample from this post within a Google Sheets add-on with drive.file scope

With a few changes as follow
- using an api key from the same project
- removing the global drive access line, because the script uses drive.file scope
DriveApp.getRootFolder();

- adding a call to a server-side function at the end of pickerCallback within PICKED action
google.script.run.testingAccessToFile(id);

- whereas 
function testingAccessToFile(fid) {
 
var r = Drive.Files.get(fid);
 
Logger.log(r);
 
return;
}

- BUT, any file I select with the Picker, when calling testingAccessToFile(id) function server-side, it would produce the following error:
Execution failed: API call to drive.files.get failed with error: File not found: 1ciX9cRjd...file-id
- this is the typical error, when the script doesn't have access to a file

Could somebody please, help on this issue?
Thanks, Fausto

Alan Wells

unread,
Jun 17, 2019, 8:45:53 AM6/17/19
to Google Apps Script Community
I would create a separate post for this.  If the app waited, and then your app used code to access that file after the picker code was done for a couple of seconds, can the code access the file?  In other words, is it a latency issue, or is the picker failing to designate the picked file as being available to the scope.

Faustino Rodriguez

unread,
Jun 17, 2019, 9:50:37 AM6/17/19
to Google Apps Script Community
- Yes, I will eventually create a separate post for this
- No, the Script cannot access the selected file at any given time after the selection ... it's not a latency issue

My big question is
+ Are you (or somebody else) able to access a file after selecting it with the Picker?

p.s. I hope I am missing or doing something wrong
my great fear is that when they say the Picker provides access, they are talking about a client-side application that uses the Picker, but not of the GAS server-side code

Eric Koleda

unread,
Jun 17, 2019, 10:46:08 AM6/17/19
to google-apps-sc...@googlegroups.com
Hi Faustino,

I did some research, and there are two requirements needed for the drive.file + Picker integration that aren't obvious:

1) You must include the method call .setAppId('...') when setting up the PickerBuilder, setting it to the value of the project number of your project.
2) You must set at least an Open URL and 256x256 application icon in the Drive API's "Drive UI Integration" screen.

The Open URL won't be used if you don't set any MIME types or file extensions to open. The icon will show up in Drive's "Settings > Manage apps" screen.

I'll work with the technical writers to make sure this information is made clearer in the documentation.

Best,
- Eric

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/_W-NKbttfbo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.

Faustino Rodriguez

unread,
Jun 17, 2019, 11:21:14 AM6/17/19
to Google Apps Script Community
Thanks a lot @Eric for your valuable support, as usually !!

- Just by doing point #1 below (.setAppId() ), the Script gets access to the Picker selected file

+ Should I do #2 as well?
- What should I enter as the 'Open URL' ?
- for my testing, I am using .setQuery()

Eric Koleda

unread,
Jun 17, 2019, 11:30:42 AM6/17/19
to google-apps-sc...@googlegroups.com
Hmm, in my testing it wouldn't work until #2 was complete. You're sure you never entered information into that screen before?

- Eric

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/_W-NKbttfbo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.

Faustino Rodriguez

unread,
Jun 17, 2019, 11:35:00 AM6/17/19
to Google Apps Script Community
No, I didn't, never seen that screen before

But, just in case I just did as follow
- add an application icon 128x128
- and set the 'Open URL' as
https://drive.google.com

Everything works fine now (so far)

What a relief !!

On Monday, June 17, 2019 at 11:30:42 AM UTC-4, Eric Koleda wrote:
Hmm, in my testing it wouldn't work until #2 was complete. You're sure you never entered information into that screen before?

- Eric

On Mon, Jun 17, 2019 at 11:21 AM Faustino Rodriguez <fau...@thexs.ca> wrote:
Thanks a lot @Eric for your valuable support, as usually !!

- Just by doing point #1 below (.setAppId() ), the Script gets access to the Picker selected file

+ Should I do #2 as well?
- What should I enter as the 'Open URL' ?
- for my testing, I am using .setQuery()

On Monday, June 17, 2019 at 10:46:08 AM UTC-4, Eric Koleda wrote:
Hi Faustino,

I did some research, and there are two requirements needed for the drive.file + Picker integration that aren't obvious:

1) You must include the method call .setAppId('...') when setting up the PickerBuilder, setting it to the value of the project number of your project.
2) You must set at least an Open URL and 256x256 application icon in the Drive API's "Drive UI Integration" screen.

The Open URL won't be used if you don't set any MIME types or file extensions to open. The icon will show up in Drive's "Settings > Manage apps" screen.

I'll work with the technical writers to make sure this information is made clearer in the documentation.

Best,
- Eric

On Mon, Jun 17, 2019 at 9:50 AM Faustino Rodriguez <fau...@thexs.ca> wrote:

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/_W-NKbttfbo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-community+unsub...@googlegroups.com.

Alan Wells

unread,
Jun 17, 2019, 12:03:24 PM6/17/19
to google-apps-sc...@googlegroups.com
I haven't tested yet.  Was working on getting the picker wired up.  I don't know if I use advanced Drive service after picking, but I may create a new sheet tab after picking.  But, whatever the situation is, I'll let you know.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

Eric Koleda

unread,
Jun 17, 2019, 12:23:36 PM6/17/19
to google-apps-sc...@googlegroups.com
I did another test, and it does seem like the Drive UI integration isn't required. Perhaps I was just getting some stale results before.

- Eric

You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/_W-NKbttfbo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.

Faustino Rodriguez

unread,
Jun 17, 2019, 1:02:34 PM6/17/19
to Google Apps Script Community
Excellent, the simpler the better
+ Should I remove what I did there (icon and open-url) or that won't hurt?

Eric Koleda

unread,
Jun 19, 2019, 10:11:22 AM6/19/19
to google-apps-sc...@googlegroups.com
It shouldn't hurt.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/_W-NKbttfbo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.

Faustino Rodriguez

unread,
Jun 19, 2019, 2:04:02 PM6/19/19
to Google Apps Script Community
Just a "minor issue" I found
- If the user Chrome browser is blocking third-party cookies, the Google file Picker won't work
- It will show a Google sign-in dialog instead of the files list and trying to do so will fail (it shows and closes the select account to sign-in)

We don't use cookies, but the Picker might be using them
This problem is reported on the web at least since 2012

@Eric: Is that the intended behavior?
- I don't see why the Picker likes the cookies

Screenshot 2019-06-19 at 1.55.31 PM.png

Eric Koleda

unread,
Jun 21, 2019, 9:07:59 AM6/21/19
to google-apps-sc...@googlegroups.com
Yes, the Picker does require the Google sign-in cookie to be present. Because it displays file details that the application doesn't have access to yet (before the file is picked) it can't rely on the OAuth token alone, otherwise developers could reverse-engineer it's requests and get access they shouldn't.

- Eric

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/_W-NKbttfbo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.

Faustino Rodriguez

unread,
Jun 21, 2019, 9:14:02 AM6/21/19
to Google Apps Script Community
Thanks @Eric
It would be good to have that documented (if it's not yet) in the Picker Api page
- I had to spend a few hours to find out ...

Troy Christmas

unread,
Jul 29, 2019, 6:16:08 AM7/29/19
to Google Apps Script Community
@Eric, Thanks for helping and appearing on TU.  

Unfortunately, for my application, the user doesn't know what file to authorize until they create/open a new file and then they only need to authorize the currently open file.  Because of this the file picker is overkill if not useless.  I've read that the File Picker is optional, but if I have the file ID already, is there another method to go through the Oauth flow for drive.file scope without the file picker?

Thanks in advance,
Troy
To unsubscribe from this group and all its topics, send an email to google-apps-script-community+unsub...@googlegroups.com.

Eric Koleda

unread,
Jul 29, 2019, 9:54:47 AM7/29/19
to google-apps-sc...@googlegroups.com
Files created by your application are automatically available to the drive.file scope. Likewise, files the user has opened with your application using the "Open With" integration in the Drive UI. However, there is no way to activate the drive.file scope for an arbitrary file ID.

- Eric

To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/_W-NKbttfbo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/04c2f618-3458-458f-b3e5-22685efc33f7%40googlegroups.com.

Troy Christmas

unread,
Jul 30, 2019, 1:11:34 AM7/30/19
to Google Apps Script Community
@Eric, Thanks for your quick and clear reply.  Not the answer I wanted, but it is a clear answer.  

If I decide to use the picker method and the user choose the then current Google Doc, do I get a new token for that same user every time they do this over the course of time?  And, does the new token apply to the one file or all files previous authorized?  Again, our goal is to subscribe for Push notifications for the particular file(s) to access them long after the initial grant of authority.

Thanks for your time.
To unsubscribe from this group and all its topics, send an email to google-apps-script-community+unsub...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/_W-NKbttfbo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-community+unsub...@googlegroups.com.

Steven Bazyl

unread,
Jul 30, 2019, 11:45:13 AM7/30/19
to google-apps-sc...@googlegroups.com
On Mon, Jul 29, 2019 at 11:11 PM Troy Christmas <troy4ch...@gmail.com> wrote:
@Eric, Thanks for your quick and clear reply.  Not the answer I wanted, but it is a clear answer.  

If I decide to use the picker method and the user choose the then current Google Doc, do I get a new token for that same user every time they do this over the course of time?  And, does the new token apply to the one file or all files previous authorized?  Again, our goal is to subscribe for Push notifications for the particular file(s) to access them long after the initial grant of authority.


Authorization is bound to the app/project, not the token. So yes, any time you get a new token during authorization or a refresh it'll be good for the cumulative set of files authorized.
 
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/_W-NKbttfbo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/99375947-5cd2-44bb-a445-e524e5c22019%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages