I am writing a google apps script to process bulk add/remove editors for some new Google Sites.
I am aware that google apps script currently doesn't support new google sites so I am trying to use DriveApp to manage the editors.
However the script doesn't work and returns the following:
Exception: Service error: Drive
whenever file.addEditor() or file.removeEditor() is used. I guess this just doesn't work for new Google Sites.
Are there other workarounds?
Make sure you're using the correct FileId with Sites as it's not quite as simple to acquire compared to other file types on Google Drive. When you're editing a Site page, the FileId can be found in the URL between /d/ and /p/.
Example: https://sites.google.com/d/????? this the file id ?????/p/!!!! not here !!!!/edit
I just successfully ran the below code to add/remove editors of a new Google Site.
const zFile= DriveApp.getFileById("????? this the file id ?????");
function addEditor(){
zFile.addEditor("pgsystemtester#gmail.com");
}
function removeEditor(){
zFile.removeEditor("pgsystemtester#gmail.com");
}
Related
I am building a Container Bound Script using AppsScript wrt Google Sheets.
I am taking input by adding a menu on the google sheet as shown below,
And when clicked, prompted with a HTML form, in which we can upload a PDF, which is saved on Google Drive and the information regarding the file upload in saved on the google sheets, but I also want to send to a FastAPI running locally on my machine.
File Information stored on Google Sheets
Code for saving on Google Drive
function uploadFilesToGoogleDrive(data,name,type){
var datafile = Utilities.base64Decode(data)
//create a new blob with decode data, name, type
var blob2 = Utilities.newBlob(datafile, type, name);
var folder = DriveApp.getFolderById("<url>");
//Create new file (property of final user)
var newFile = folder.createFile(blob2);
var rowData = [
newFile.getName(),
newFile.getUrl(),
newFile.getDateCreated()
];
SpreadsheetApp.getActive().getSheetByName("sheet1").appendRow(rowData);
return newFile.getUrl()
}
For sending data to external API I came across Run app script function from website/localhost and Upload files from google drive to external api using google apps script
I am not getting a method through which I can send to API running locally without localtunnel.
It's not possible to run a Google Apps Scripts project locally, Google Apps Scripts projects run on Google Servers.
You can find more information here.
In your case, the only viable way I can think of for you to can call an API being served locally, would be to expose the appropriate endpoints from your API to the web. That way, the Google Servers responsible to run your script will have access to your API.
I understand that perhaps this solution is against the purpose of having an API server locally (since it won't be locally anymore), however Google Apps Script is designed to work on the Cloud.
In any case, you may find the Apps Script Class UrlFetchApp useful for making HTTP requests for your own API of any other.
I have a Google Script library that is used by at least 100 other scripts (some that are bound to spreadsheets/documents, some that are not). How can I find all of these client scripts that reference my library script?
More specifically, I need to be able to add a new feature into the library that requires new permissions that I (the user) must grant. The client scripts won't run if I just add this feature to the library without granting the permissions to each of the client scripts. So ultimately, I need to give this new permission to each of the clients. And if I knew what scripts were actually using this library, I could do that manually for each one. But I need to URL's or ID's or something for each of those scripts.
Answer:
Unfortunately this is not possible to do.
More Information
It is possible to get a list of standalone Scripts from your Drive, though scripts bound to a file can not be searched for using regular searching methods.
It is possible, using the help of this Google Account page to get a list of all the Apps that have access to your account, though only files you have authorised will appear here, and apps which are not just those created by you in Apps Script will appear there (for example, other add-ons or even Android Apps bound to your account appear here).
A Partial Workaround:
Using Google Apps Script, you can list all Apps Script Projects that you own with help of the MimeType enumeration GOOGLE_APPS_SCRIPT
var scripts = DriveApp.getFilesByType(MimeType.GOOGLE_APPS_SCRIPT);
var arr =[ ];
while (scripts.hasNext()) {
var script = scripts.next();
arr.push(script)
}
Logger.log(arr);
Or even just searching for type:script in Drive, however this only returns a list of scripts that are not bound to a file.
You can then use regular Google Drive search terms to find which of these files contain, for example, a unique method name that the library uses. I am aware this isn't a perfect solution and you would still have to look for projects bound to a file using the above webpage.
Feature Request:
It appears that back in 2014 a feature request for this was made on Google's Issue Tracker, though I would suggest creating another feature request for this here as it was marked as a duplicate of another issue. You can make a feature request under the correct Apps Script component here.
References:
Google Apps Script - Enum MimeType
Google Drive Search Query Terms
Apps with access to your account
Google's Issue Tracker
Feature Request: Listing and searching for container bound scripts
Create an Apps Script Feature Request
What I want to do
Copy a google sheet programmatically via API.
Change the copied sheet's cloud platform project to the original sheets project, when copied Google creates a new google platform project, that's not what I want.
Get the script id of the copied sheet.
All of the above only programmatically, I already know how to do these things manually by clicking menu's.
What I have already tried:
This google documentation article tells me how to change a platform project manually, I want to do the same thing via some API that Google may be providing.
You can copy a sheet programmatically via this API, however you can't get the associated script id or the project and it doesn't let me set the cloud platform project.
I know how to get the script id from within the sheet, I want to do this from outside the sheet.
Note that the API's I need have to be accessible via outside the sheet, via a program that I host myself.
I realized what I was really looking for were Add on's. Via that I can keep the apps script project as one which solves all my requirements.
Read more about App Script addons from this google doc page: https://developers.google.com/apps-script/add-ons/
I am using a google apps script and writing a script for my google spreadsheet. I need to take the windows login id so that I can know who is filling up the spreadsheet.
All my searches in the web yield the code that looks like this:
var wshell = new ActiveXObject("WScript.Shell");
alert(wshell.ExpandEnvironmentStrings("%USERNAME%"));
But google apps throws an error saying ActiveX not found. I am new to JavaScript and Google Apps.
Thanks a lot.
This is not possible nor should it be as it would be a huge security issue.
Explains more: JavaScript - How to get the name of the current user
Reason it doesn't work on windows in explorer is because your google-apps-script code get sanitized by google-caja.
I've got the current code to open a google spreadsheet
var spreadSheet = SpreadsheetApp.openById(docId);
Which works fine for converted google spreadsheets.
But how do I open an unconverted xls file using the google sheets app? (It defaults to using the google drive viewer when I do it like above mentioned)
Thanks
Going from another post which is asking a similar question I don't think it's currently possible. There's an open issue (issue 1019) requesting the ability to programmatically convert documents.
It's possible through Google App Scripts
https://code.google.com/p/google-apps-script-issues/issues/detail?id=1019#c15
Strange that Google Drive will allow other apps to be set as default for certain types of files. But won't let you set gsheets or doc itself as default for these file types.
Its kind of odd that a class Product innovator which includes awesome keyboard shortcuts for its products, will let you live with no option but to point checkbox, click on Open with and select its app to open.