Stack Tracer
Stack Tracer

Reputation: 1028

Google Script Full Account Access

So, I am writing a Google Apps Script, but every time I change the script to do something new, it needs to be reauthorized. Is there a way to "pre-authorize" all of these permissions for a script so that you no longer need to be prompted?

I know that the highest level of permissions that can be given to an app is "Full account access", so if anyone knows how to give a script that level of permission, I would really appreciate finding out.

Upvotes: 0

Views: 972

Answers (1)

Mogsdad
Mogsdad

Reputation: 45750

If you really want to get a script authorized for pretty much everything in one shot, read on!

It's not consistent with Google's security policies to provide mindless authorization, so you find a button anywhere to do that. But you're right - a script containing every API call will trigger each specific authorization.

You could go through the docs and look up every method, or even use auto-complete to get them all, but here's a trick to automate the process.

All the Google Apps Services are properties of the this object, and their methods are in turn properties of them. So you can walk the this object definition to build a list of all GAS methods, and assemble a function that includes all them, just for a one-pass super-authorization.

Code:

function buildauthFuncInside() {
  var authFuncInside = "return;";  // safety in case someone calls the function
  for (var maybeService in this) {
    if (typeof this[maybeService] !== 'object') continue;
    var service = this[maybeService];
    var serviceName = service.toString();
    if (serviceName == 0) continue;  // Skip 'funny' functions, like "BigNumber"
    for (var maybeFunction in service) {
      if (typeof service[maybeFunction] == 'function') {
        // Note: name is a non-standard property of function objects
        authFuncInside += serviceName+"."+service[maybeFunction].name+"();"
      }
    }
  }
  var authFunc = "function authFunc() {"+authFuncInside+"}";

  // Copy the value of authFunc from the debugger, paste into the editor,
  // remove the quotes, and you have a super-authorization function.
  debugger;
}

This function builds a string that contains a function with every known method, excluding Advanced Services. Paste the code into your script, run it in debug mode, and be ready for it to pause at the end.

As the comment says: Copy the value of authFunc from the debugger, paste into the editor, remove the quotes, and you have a super-authorization function. Today, here's what you'd get:

function authFunc() { Browser.msgBox(); Browser.toString(); Browser.inputBox(); CacheService.getUserCache(); CacheService.getScriptCache(); CacheService.getDocumentCache(); CacheService.getPrivateCache(); CacheService.toString(); CacheService.getPublicCache(); CalendarApp.getTimeZone(); CalendarApp.createEventSeries(); CalendarApp.isMyPrimaryCalendar(); CalendarApp.createAllDayEvent(); CalendarApp.subscribeToCalendar(); CalendarApp.setColor(); CalendarApp.getEventSeriesById(); CalendarApp.setHidden(); CalendarApp.getTitle(); CalendarApp.newRecurrence(); CalendarApp.getAllOwnedCalendars(); CalendarApp.getOwnedCalendarById(); CalendarApp.getId(); CalendarApp.setTimeZone(); CalendarApp.getColor(); CalendarApp.getDescription(); CalendarApp.getDefaultCalendar(); CalendarApp.getEventsForDay(); CalendarApp.openByName(); CalendarApp.createCalendar(); CalendarApp.getAllCalendars(); CalendarApp.openByEmailAddress(); CalendarApp.getCalendarById(); CalendarApp.getOwnedCalendarsByName(); CalendarApp.createAllDayEventSeries(); CalendarApp.isHidden(); CalendarApp.createEvent(); CalendarApp.getEvents(); CalendarApp.isSelected(); CalendarApp.setDescription(); CalendarApp.getName(); CalendarApp.toString(); CalendarApp.setName(); CalendarApp.createEventFromDescription(); CalendarApp.getCalendarsByName(); CalendarApp.isOwnedByMe(); CalendarApp.setSelected(); Charts.newTextStyle(); Charts.newDashboardPanel(); Charts.newColumnChart(); Charts.newScatterChart(); Charts.newNumberRangeFilter(); Charts.newTableChart(); Charts.newPieChart(); Charts.newDataViewDefinition(); Charts.newCategoryFilter(); Charts.newStringFilter(); Charts.newAreaChart(); Charts.newDataTable(); Charts.toString(); Charts.newBarChart(); Charts.newLineChart(); ContactsApp.getContactsByPhone(); ContactsApp.getContactsByCustomField(); ContactsApp.getContactsByAddress(); ContactsApp.deleteContact(); ContactsApp.getAllContacts(); ContactsApp.getContactGroupById(); ContactsApp.findContactGroup(); ContactsApp.getContactsByDate(); ContactsApp.createContact(); ContactsApp.getContactsByNotes(); ContactsApp.getContactsByIM(); ContactsApp.getContactsByUrl(); ContactsApp.getContacts(); ContactsApp.getContactsByEmailAddress(); ContactsApp.findByEmailAddress(); ContactsApp.getContactsByGroup(); ContactsApp.getContactsByCompany(); ContactsApp.getContact(); ContactsApp.deleteContactGroup(); ContactsApp.getContactGroups(); ContactsApp.getContactGroup(); ContactsApp.createContactGroup(); ContactsApp.getContactsByJobTitle(); ContactsApp.getContactsByName(); ContactsApp.toString(); ContactsApp.getContactById(); ContentService.createTextOutput(); ContentService.toString(); DocumentApp.getUi(); DocumentApp.openByUrl(); DocumentApp.toString(); DocumentApp.getActiveDocument(); DocumentApp.create(); DocumentApp.openById(); Drive.removeFolder(); Drive.getFolders(); Drive.getFolderById(); Drive.getTrashedFiles(); Drive.addFolder(); Drive.addFile(); Drive.searchFolders(); Drive.createFolder(); Drive.getTrashedFolders(); Drive.getStorageLimit(); Drive.createFile(); Drive.getFilesByType(); Drive.removeFile(); Drive.getFileById(); Drive.continueFileIterator(); Drive.getFilesByName(); Drive.getFiles(); Drive.getRootFolder(); Drive.getFoldersByName(); Drive.toString(); Drive.getStorageUsed(); Drive.continueFolderIterator(); Drive.searchFiles(); FormApp.getActiveForm(); FormApp.getUi(); FormApp.openByUrl(); FormApp.toString(); FormApp.create(); FormApp.openById(); GmailApp.getAliases(); GmailApp.moveThreadToInbox(); GmailApp.getMessagesForThread(); GmailApp.markMessageUnread(); GmailApp.getPriorityInboxUnreadCount(); GmailApp.search(); GmailApp.markThreadRead(); GmailApp.markMessagesUnread(); GmailApp.markThreadsUnread(); GmailApp.getThreadById(); GmailApp.markThreadsRead(); GmailApp.refreshThread(); GmailApp.getMessageById(); GmailApp.markMessageRead(); GmailApp.getUserLabels(); GmailApp.refreshThreads(); GmailApp.toString(); GmailApp.sendEmail(); GmailApp.unstarMessage(); GmailApp.moveThreadToSpam(); GmailApp.getTrashThreads(); GmailApp.markThreadUnimportant(); GmailApp.getUserLabelByName(); GmailApp.moveThreadToArchive(); GmailApp.getSpamThreads(); GmailApp.moveThreadToTrash(); GmailApp.moveThreadsToArchive(); GmailApp.starMessages(); GmailApp.moveMessagesToTrash(); GmailApp.deleteLabel(); GmailApp.getMessagesForThreads(); GmailApp.moveMessageToTrash(); GmailApp.getSpamUnreadCount(); GmailApp.refreshMessages(); GmailApp.markThreadUnread(); GmailApp.getDraftMessages(); GmailApp.moveThreadsToSpam(); GmailApp.unstarMessages(); GmailApp.getChatThreads(); GmailApp.getPriorityInboxThreads(); GmailApp.markThreadImportant(); GmailApp.getStarredThreads(); GmailApp.getInboxThreads(); GmailApp.createLabel(); GmailApp.starMessage(); GmailApp.moveThreadsToInbox(); GmailApp.markThreadsUnimportant(); GmailApp.moveThreadsToTrash(); GmailApp.markThreadsImportant(); GmailApp.refreshMessage(); GmailApp.getInboxUnreadCount(); GmailApp.getStarredUnreadCount(); GmailApp.markMessagesRead(); GroupsApp.getGroupByEmail(); GroupsApp.getGroups(); GroupsApp.toString(); HomeroomService.toString(); HtmlService.createTemplateFromFile(); HtmlService.getUserAgent(); HtmlService.toString(); HtmlService.initTemplate(); HtmlService.createHtmlOutputFromFile(); HtmlService.createHtmlOutput(); HtmlService.createTemplate(); Jdbc.newTimestamp(); Jdbc.newTime(); Jdbc.newDate(); Jdbc.parseTime(); Jdbc.getCloudSqlConnection(); Jdbc.parseTimestamp(); Jdbc.toString(); Jdbc.getConnection(); Jdbc.parseDate(); LanguageApp.toString(); LanguageApp.translate(); LinearOptimizationService.createEngine(); LinearOptimizationService.toString(); LockService.getPublicLock(); LockService.toString(); LockService.getDocumentLock(); LockService.getPrivateLock(); LockService.getUserLock(); LockService.getScriptLock(); Logger.clear(); Logger.getLog(); Logger.finest(); Logger.finer(); Logger.config(); Logger.toString(); Logger.severe(); Logger.fine(); Logger.log(); Logger.warning(); Logger.info(); MailApp.getRemainingDailyQuota(); MailApp.createMessage(); MailApp.toString(); MailApp.sendEmail(); Maps.encodePolyline(); Maps.decodePolyline(); Maps.newElevationSampler(); Maps.toString(); Maps.newGeocoder(); Maps.newStaticMap(); Maps.setAuthentication(); Maps.newDirectionFinder(); MimeType.toString(); PropertiesService.getScriptProperties(); PropertiesService.toString(); PropertiesService.getUserProperties(); PropertiesService.getDocumentProperties(); ScriptApp.newStateToken(); ScriptApp.getProjectTriggers(); ScriptApp.newTrigger(); ScriptApp.getOAuthToken(); ScriptApp.getUserTriggers(); ScriptApp.getScriptTriggers(); ScriptApp.getInstallationSource(); ScriptApp.getResource(); ScriptApp.toString(); ScriptApp.invalidateAuth(); ScriptApp.deleteTrigger(); ScriptApp.getService(); ScriptApp.getProjectKey(); ScriptApp.getAuthorizationInfo(); ScriptProperties.deleteAllProperties(); ScriptProperties.getKeys(); ScriptProperties.setProperties(); ScriptProperties.getProperty(); ScriptProperties.toString(); ScriptProperties.deleteProperty(); ScriptProperties.setProperty(); ScriptProperties.getProperties(); Session.getTimeZone(); Session.getScriptTimeZone(); Session.getUser(); Session.getActiveUserLocale(); Session.getActiveUser(); Session.toString(); Session.getEffectiveUser(); SitesApp.getActivePage(); SitesApp.copySite(); SitesApp.getActiveSite(); SitesApp.getPageByUrl(); SitesApp.getSite(); SitesApp.createSite(); SitesApp.getSites(); SitesApp.getAllSites(); SitesApp.toString(); SitesApp.getSiteByUrl(); SoapService.wsdlService(); SoapService.wsdl(); SoapService.toString(); SpreadsheetApp.getActiveSpreadsheet(); SpreadsheetApp.getActiveRange(); SpreadsheetApp.openByUrl(); SpreadsheetApp.setActiveRange(); SpreadsheetApp.create(); SpreadsheetApp.openById(); SpreadsheetApp.open(); SpreadsheetApp.getUi(); SpreadsheetApp.getActive(); SpreadsheetApp.setActiveSpreadsheet(); SpreadsheetApp.flush(); SpreadsheetApp.getActiveSheet(); SpreadsheetApp.setActiveSheet(); SpreadsheetApp.toString(); SpreadsheetApp.newDataValidation(); SpreadsheetApp.openByKey(); UiApp.createApplication(); UiApp.getUserAgent(); UiApp.getActiveApplication(); UiApp.toString(); UrlFetchApp.fetch(); UrlFetchApp.addOAuthService(); UrlFetchApp.toString(); UrlFetchApp.getRequest(); UrlFetchApp.removeOAuthService(); UserProperties.deleteAllProperties(); UserProperties.getKeys(); UserProperties.setProperties(); UserProperties.getProperty(); UserProperties.toString(); UserProperties.deleteProperty(); UserProperties.setProperty(); UserProperties.getProperties(); Utilities.formatDate(); Utilities.computeHmacSha256Signature(); Utilities.zip(); Utilities.sleepAndThrow(); Utilities.computeDigest(); Utilities.jsonParse(); Utilities.base64EncodeWebSafe(); Utilities.unzip(); Utilities.base64Encode(); Utilities.sleep(); Utilities.base64Decode(); Utilities.computeHmacSignature(); Utilities.formatString(); Utilities.base64DecodeWebSafe(); Utilities.newBlob(); Utilities.jsonStringify(); Utilities.toString(); Utilities.validateSleepTime(); Utilities.parseCsv(); Xml.element(); Xml.text(); Xml.declaration(); Xml.parseJS(); Xml.attribute(); Xml.xml(); Xml.xmlns(); Xml.namespace(); Xml.document(); Xml.name(); Xml.empty(); Xml.toString(); Xml.comment(); Xml.parse(); Xml.processingInstruction(); XmlService.createDocType(); XmlService.getCompactFormat(); XmlService.getPrettyFormat(); XmlService.getNoNamespace(); XmlService.getRawFormat(); XmlService.createComment(); XmlService.createDocument(); XmlService.toString(); XmlService.getXmlNamespace(); XmlService.parse(); XmlService.getNamespace(); XmlService.createElement(); XmlService.createCdata(); XmlService.createText(); } 

Now, run or debug anything in your script, and you'll get a super authorization message.

Upvotes: 3

Related Questions