auth/drive.file scope will not allow access to current document

73 views
Skip to first unread message

Alan Wells

unread,
Jun 17, 2019, 5:02:42 PM6/17/19
to Google Apps Script Community
The auth/drive.file scope will NOT allow access to the current document.  The current document was never selected by the Google Picker, and if wasn't created by the add-on, which if probably won't be, then your code can't access the file that the add-on is installed in.  The reason that I want to get the file that the current add-on is installed in, is to get the parent folder.  And I want the code to get the parent folder of the document because when the add-on creates a new file, I don't want all new files put into the the root "My Drive"  I'm sure that the user doesn't want new files put into the root either.  So, I'll need to add a folder picker to get the folder ID if the user wants the file put anywhere but the root drive.  Previously, I just had the code get the current doc ID, then get the file, then get the parent folder of the file.  But if you can't get the active doc file, then that's not possible.

The auth/drive.file scope should allow access to the file that the add-on has been enabled in.

Faustino Rodriguez

unread,
Jun 18, 2019, 6:41:13 AM6/18/19
to Google Apps Script Community
There is no way to get the parent folder of a file with currentonly and drive.file scopes
- But you can create a folder hanging from root to hold the files the add-on create there

Alan Wells

unread,
Jun 18, 2019, 7:46:14 AM6/18/19
to google-apps-sc...@googlegroups.com
Good idea.  I think I'll implement that.  I did add a folder picker and the code will add a file directly to a folder with advanced drive service.  So, another hurdle overcome.

--
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/6d8d22e1-a629-4884-87b0-08b9b8b7e0c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alan Wells

unread,
Jun 18, 2019, 8:15:32 AM6/18/19
to Google Apps Script Community
The "auth/drive.file" scope won't allow a new folder to be created, so it's back to putting the file in the root if the user doesn't pick a folder.


On Tuesday, June 18, 2019 at 7:46:14 AM UTC-4, Alan Wells wrote:
Good idea.  I think I'll implement that.  I did add a folder picker and the code will add a file directly to a folder with advanced drive service.  So, another hurdle overcome.

Faustino Rodriguez

unread,
Jun 18, 2019, 8:26:25 AM6/18/19
to google-apps-sc...@googlegroups.com
Yes, it does allow to create a new folder
Try as follow ...

function createFolder(folderName, parentFolderId) {
 
var resource = {
    title
: folderName,
    mimeType
: "application/vnd.google-apps.folder"
 
};
 
if (parentFolderId) resource.parents = [{ id: parentFolderId }];
 
return Drive.Files.insert(resource);
}

p.s. parentFolderId defaults to 'root'

Alan Wells

unread,
Jun 18, 2019, 9:08:20 AM6/18/19
to google-apps-sc...@googlegroups.com
It worked.  That is great.  Thank you for your help.

On Tue, Jun 18, 2019 at 8:26 AM Faustino Rodriguez <fau...@thexs.ca> wrote:
Yes, it does allow to create a new folder
Try as follow ...

function createFolder(folderName, parentFolderId) {
 
var resource = {
    title
: folderName,
    mimeType
: "application/vnd.google-apps.folder"
 
};
 
if (parentFolderId) resource.parents = [{ id: parentFolderId }];

 
return insert(resource);
}

p.s. parentFolderId defaults to 'root'

On Tuesday, June 18, 2019 at 8:15:32 AM UTC-4, aj.addons wrote:
The "auth/drive.file" scope won't allow a new folder to be created, so it's back to putting the file in the root if the user doesn't pick a folder.

On Tuesday, June 18, 2019 at 7:46:14 AM UTC-4, Alan Wells wrote:
Good idea.  I think I'll implement that.  I did add a folder picker and the code will add a file directly to a folder with advanced drive service.  So, another hurdle overcome.

On Tue, Jun 18, 2019 at 6:41 AM Faustino Rodriguez wrote:
There is no way to get the parent folder of a file with currentonly and drive.file scopes
- But you can create a folder hanging from root to hold the files the add-on create there

--
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.
Reply all
Reply to author
Forward
0 new messages