Google Drive SDK: Programatically pin a Google Doc revision - google-drive-api

The Google Drive API v2 Drive.revisions.update method allows the setting of a pinned parameter so that the particular revision is never automatically purged. However as the documentation says, this does not apply for Google Docs. How can we pin a revision so it is never deleted? I have an app that depends on tracking and retreiving certain revisions at a later point in time.
Any suggestions on how this can be done?

Google docs (as well as all native google formats like spreadsheet) does NOT get any revisions deleted automatically, thus there is no need to pin revisions.
If you were referring to .doc, those aren't Google docs.
I couldn't find a reference inside the documentation, but I did find an official reference in their marketing page:
https://apps.google.com/intx/en/products/docs/ says:
Unlimited revision history
Track changes made to your documents and undo anything you choose. Previous versions are kept indefinitely and they don't count toward your storage.

It seems that Google is clear about this.
pinned - This will only be populated and can only be modified on files with content stored in Drive which are not Google Docs.
Try converting your revision files to pdf (non Google Doc). You can then keep the revisions using pinned = true.

Related

How do I name the current version of a Google spreadsheet, document or presentation using Google Apps Script?

I'm trying to give the current version of a Google spreadsheet a name using Google Apps Script. In the GUI I would do File -> Version history -> Name current version but since I need to do this to multiple files, I want to achieve this using a script.
I've found the revisions reference but that's not helping much.
This question touches on a similar topic, but I've found the revisions.items.splice(-1) doesn't always list the current version but rather the latest version.
This is not possible to do at this moment. I've found a similar Feature Request. You can click on the star next to the issue number to give more priority to the request and to receive updates.
It's not exactly the same but since it's asking for API support, "update the revisions" would presumably be supported too.

Can one iterate through bound scripts and edit their manifest files via a script?

I am building an application that will have many users, each of whom will have many Google documents. Each doc will have a custom menu and that custom menu will invoke a library script. I may need or want to change the coding in that library script from time to time.
As changes to a library script must be "saved" as a new version in order for the changed version to be passed on to client scripts (in my case, the scripts bound to Google Docs), I need a way that users can "batch" update the version number in their docs' bound script appsscript.json
file.
I have researched this issue and there seems to be two general alternatives: set the client scripts' library mode to "Developmental" or use an add-on.
The problem with the former is that it won't work unless the users are all granted edit mode access to the library script (which seems particularly a bad idea as the users may well not even be known to me).
The problem with the later is essentially complication and cost. If I make the add-on private, it only works for users in the same domain which means I have to create a G-Suite domain (and pay at least (as of this writing) $72 per year per user—a non-starter for this project).
If I make the add-on public, in addition to the complication, I have to sign up to the Google Cloud Platform and the costs for that require one to navigate a veritable maze of choices and alternatives such that at this point, I really have no idea what the cost per service or user would be.
Below I present some "mock-up" code that should at least indicate the direction I am trying to go.
function upDate() {
var version = 23
var scripts = "https://script.google.com/u/0/home"
//while (scripts.hasNext()) {
//var script = files.next();
//Note: All of the script's have the same name as they commence life bound to a template, which template is duplicated to create the rest of the user's docs
if( scriptName = ScriptName){
//set.dependencies.enabledAdvancedServices[].version
}
}
I don't even know if it's possible to step through bound scripts the way one step's through files in a Google Drive, so that is the first question. Then, the second question is whether, assuming you can step through the scripts one by one, you can change a manifest value—in this case, the version number.
One cannot step through container-bound scripts as they are (no longer) located in one's Google Drive. Moreover, despite Google's documentation about using a "stable" value in the version section of the manifest, that documentation appears erroneous. Finally, one cannot programmatically edit standalone scripts.
However, there is a workaround. What I ended up doing was writing a script that steps through all of the involved Google Docs and copies them to a blank template (i.e., in effect, duplicates them all). That blank template has the bound script installed in it with the new version number of the library. Then, delete original docs (via the same script) and voilà, batch update to all of the target docs is accomplished. (One drawback of this is: if Google Doc revision history is important to you, be advised this gambit jettisons that (unless you keep the original versions).

Revert revision for Google Drive Spreadsheet using API

I am required to provide revision-revert functionality for Google Drive Spreadsheet (Without losing revision history).
As far as v4 SpreadSheet API doesn't have revision functionality. I am trying to use Google Drive API. I can successfully get revisions list with this API and get the specific revision.
But I can't find a way to roll back file on the target revision. Is there the way to do this using Google API calls?
Revisions.list is used to get the versions list. To actually go to the version, use revisions.get. You will be asked to provide a revisionId (which you obtained from revisions.list).
You can use Try-it to do that.

Is there a way to access Google Docs' new Action Items via the Drive API?

The Drive API allows access to Comments and Changes on documents but I don't see the new action items feature in the reference documentation.
Is there a way to perform any of the standard CRUD operations on them: get a list of them, get their properties, add new ones, modify them, etc.?
I'm actually interested in doing this through Google Apps Script but I understand that even Comments are only available in the Drive API, so I suspect if there's a way to do it it would be through the Drive API first.

Google Apps Script access Drive SDK API

Is there a way to use the Google Drive API's from Google Apps Script. I am aware of the DocsList Service, which allows you to look at folders and files , however what about all the other API's in Google Drive (Files,About,Changes,Children,Parents,Permissions,Revisions,Apps,Comments,Replies). For example, is there API access to add Comments to files from Google Apps Script.
Apps Script has the ability to access Google API's, but you need to explicitly enable them before they can be used.
In the code editor, choose RESOURCES, ADVANCED GOOGLE SERVICES
Click the OFF button, to turn the service ON.
Before you close the dialog box, click the link at the bottom to open up the API Manager.
Once you've completed those two steps, the Drive API is available inside of Apps Script. Type the key word Drive then type a period, and available methods will show up in a list.
Methods
get - Gets a file's metadata by ID.
insert - Insert a new file.
patch - Updates file metadata. This method supports patch semantics.
update - Updates file metadata and/or content.
copy - Creates a copy of the specified file.
delete - Permanently deletes a file by ID. Skips the trash.
list - Lists the user's files.
touch - Set the file's updated time to the current server time.
trash - Moves a file to the trash
untrash - Restores a file from the trash.
watch - Start watching for changes to a file.
emptyTrash - Permanently deletes all of the user's trashed files.
https://developers.google.com/drive/v2/reference/files#methods
(Google-Apps-Script=GAS) Drive Services added 2013.05.13 (to be announced at the 2013 Google I/O 2 days later) is apparently-exactly designed to replace the prior API(DocsList) and allow GAS to access the Google Drive SDK, though that functionality is currently not mentioned (why?) from those official docs but it is most certainly suggested by the new new API name "Drive" and is stated at as the purpose by Google's great demo video "Integrate Google Drive with Google Apps Script — Google I/O 2013" and "Drive SDK" is mentioned in by the search functions as searchFiles(String).
And Drive Services works (I'm using it; and though I could think of many improvements, haven't found any bugs of memory) including it works for useful apps (see the the video above for one of the most impressive ones I've seen) but it isn't complete (including doesn't expose the full Drive SDK) including:
it doesn't (yet?) allow one to access prior versions of content (as that vide plus (the enhancement request: Google Search for "Issue 2811: Access the document revisions using DriveApp"),
control the indexing status & method of content,
one can't get a list of a file or folder's accessors (apparently deliberately says the video; but using the prior DocsList or Library mentioned seems like it would be a workaround).
I'd have included more links to help out but I'm a new poster here so the editor's telling me "You need at least 10 reputation to post more than 2 links.".
Yes, it's possible.
Take a look at the documentation for Class File, which includes functions for obtaining and/or changing most of the attributes you've listed.
For an example of code that gets some of this info for files and folders, see this answer.
You should also have a look at this Library written by Romain Vialard, one of the GAS TC.
It provides functions that are not available directly in gas or - at least - not as simply.