Real-time Changes to Google Document / Spreadsheet / Presentation - google-drive-api

Is it possible to get a real-time notification (without extensive polling) for changes made to a Google document (document / spreadsheet / presentation)? If so, what is the model structure (if that makes sense)? Any pointers to documentation or samples would help!
The documentation at https://developers.google.com/drive/manage-changes gives an API call that returns instantly and tells you whether there have been any changes since the last one. However, this is useless you want to know almost as soon as a change has been made -- you would have to make back to back API calls every second or sooner and churn a lot of resources. The Drive Real-time API in contrast gives a way to be instantly notified of any changes without extensive and frequent polling. It does this with an HTTP call that "hangs" until there is a change ready (or a timer expires). This is a classic long-poll technique.
My question is whether such a facility exists for Google Documents / Spreadsheets / Presentations. Or is it available only for custom app-specific files other than these standard ones. If it is not available, are there any plans for making them available?
Thanks in advance!

In my knowledge - the answer is "NO". I have tried this before and could only do it with the timed polling. The API is limited to tell you only when you ask, not when something happens.
I thought of a code that is embed into document and does a self broadcast to a specific URL or some listener. My experiments were with Google App Scripts. Detail idea is to create a custom function that gets triggered on the 'Save' event. But I could go no further as there is nothing enough in documentation as per me to achieve this specific goal.
On the timelines for this availability, there are questions in the scripts forum on this, but none replied on these lines.

It looks like it, see https://developers.google.com/drive/v2/reference/changes
it has examples too
edit:
https://developers.google.com/drive/manage-changes
more info about tracking changes

The answer, I'm afraid, is no. There is currently no way for you to be notified by email when a change is made to a Drive text document. This function is available for spreadsheets, but not for text files. If your document is public, you ccan subscribe to its RSS feed to view changes, or use the Tools -> Revision History function in Drive.
There is one downloadable program, googledocsnotifier --information--, which emails you when edits are made and allows you to open the doc that was edited, but it appears that it only works when you are online. You can download it here.
Hope this helps!

Related

Limiting downloading, copying and printing for EDITORS in Google drive

I am looking to find out if it is POSSIBLE to restrict EDITORS from downloading, copying or printing a Google sheet or other documents in a Google Drive. We share sheets/documents with our customers so they can fill in the details. For that we need to make them EDITORS (so they can edit and even invite others to the party). I know that we can restrict COMMENTERS and VIEWERS from downloading, but in our case we need to prevent EDITORS.
We have a LOT of intellectual property in our sheets (custom formulas and approaches), and we would like to be able to prevent people from simply downloading it. As I understand it this SHOULD be possible using the Google Drive API, but I have not been able to figure out how to do it, yet. Looking at the API it obliquely says it MAY be possible, but it is not clear :-(
Direction, or sample code, would be VERY much appreciated.
TIA
It's not possible to restrict editors from downloading files. The documentation mentions that only commenters and viewers can be prevented from this. Then in the API docs concerning permissions and their definitions you will see that there's nothing controlling downloads either. This is just a UI change.
If you think about it, the reason is clear: Even if you manage to stop direct downloads, to anyone with at least read access to the file or API this is just a minor inconvenience. They can still read all the content and metadata from the API and replicate the file perfectly. Even viewers with copy disabled can still read the formulas from the formula bar. Sharing the Sheets file is inherently unsafe if you have confidential data in it, since a determined attacker can still get all your trade secrets easily. You're only supposed to share these files with trusted users.
My suggestion is to take a different approach. Do not share the Sheets file at all and use something else as intermediary to request data from your customers. For example:
Create a Google Form to save the responses to a Sheet. Your customers will only need to fill out the form and the sheet will be filled with data that you can handle on your side.
If you need the users to also view some information in the Sheet before filling out their info you can build an Apps Script Web App that displays only the plain data that you need to show them. With this you can hide the formulas and other sensitive information. Using templates and server functions you can allow the users to interface with the Sheet data similarly to how they do it now, but with a more restricted view. You could even allow them to edit only the data you want them to. This requires more work and is starting to delve into web development, but It's much easier than a fully fledged website since the hosting and interfacing with APIs is handled by Apps Script.
You could just create your own application and use the Sheets API to read and write data from the Sheet. This is pretty much the previous suggestion but much harder, though in the end it will give you more flexibility.
The bottom line is that sharing your Sheet in any way is akin to giving your users full database read or write access, and there's no single setting that can prevent that. Your best bet is to avoid sharing these files and use a different method to request user data.

Is there a way of seeing the script code for an action I have performed?

I am new to writing scripts in Google Apps. I am trying to script various actions in Google Docs which previously I would have done through the main user interface. Is there a way of "recording" such actions as they are carried out, analogous to recording a Macro in Excel?
For example, I am creating a Form in Google Docs. Using the main interface, I can add an Image item and upload an image from another source (Google Drive, my desktop, etc.), but I can't work out the script code that would perform this same action. Is there any way to output the script that would have carried out the same action that I have just performed?
Many thanks.
Currently, you cannot 'record' a macro.
There is an issue in the Issue tracker (issue 650) where Google have mentioned that it is not feasible at the moment (Jul 2010). You may star the issue to register your interest to the enhancement request.
I think the real issue is that the GApps scripting functions are manipulations of the underlying object model of the document. The UI also manipulates the underlying object model, but no one has yet created the functions to emulate the UI in GApps script form. Recording the actions would then be a separate step and converting the recorded actions into GApps functions would be yet another step.
So you need to be clear: is your goal to be able to record and play back UI actions, or is your goal to be able to upload an image into a GDoc? You asked about recording and that's the answer you got. Maybe if you asked about how to use GApps to add an image to a GDoc, you would get a more useful answer.
My own personal question would be:
I haven't figured out how to use the GApps documentation very
efficiently yet. I do a lot of fruitless hunting. How do I find in the
docs how to add an image to a GDoc?
I hope this helps.

Calling a Google Drive SDK from Google App Script application

i have been going around in circles here and have totally confused myself. I need some help.
I am (trying to) writing an application for a client that in concept is simple. he want a google write document with a button. the google drive account has several folders, each shared with several people. when he drops a new file in one of the folders, he wants to be able to open this write file, this file is the template for his email. he clicks the button, the system calls the changes service in the Google Drive SDK https://developers.google.com/drive/manage-changes, gets the list of files that have been added since the last time it was checked, then pull the list of people that the file has been shared with, and use the write file as a template to send that list of people an email saying their file is ready.
SO, easy enough, right?
I started by looking at the built in functions in the Google App Script API. I found this method, https://developers.google.com/apps-script/class_docslist#find in the DocsList class. problem is the description for the query simply says "the query string". So at first i tried the Drive SDK query parameters, which are
var files = DocsList.find("modifiedDate > 2012-12-20T12:00:00-08:00.");
it didn't work. that leads me to believe it is a simple full text search on the content. Thats not good enough.
That lead me into trying to call a Drive SDK method from within an App Script application. Great, we need an OLap 2 authentication. easy enough. found the objects in the script reference and hit my wall.
Client ID and Client Secret.
you see, when i create what this really is, a service account, the olap control in apps script doesn't know how to handle the encrypted json and pass it back and forth. Then when i tried to create and use an installed applications key, i get authentication errors because the controls again, don't know what to do with the workflow. and finally, when i try to create a web app key, i can't because i don't have the site host name or redirect URI. And i can't use the application key ability because since im working with files OLap 2 is required.
i used the anonymous olap for a while, but hit the limit of anonymous calls per day in the effort of trying to figure out the code a bit, thats not going to work because the guy is going to be pushing this button constantly thru the day.
i have been pounding my head on the desk over this for 5 hours now. i need some help here, can anyone give me a direction to go?
PS, yes, i know i can use the database controls and load the entire list of files into memory and compare it to the list of files in the database. problem being, we are talking tens of thousands of files. bad idea.
I wouldn't use DocsList anymore - DriveApp is supposed to be a more reliable replacement. Some of the commands have changed, so instead of find, use searchFiles. This should work more effectively (they even use a query like yours as an example).

ScriptDb and Google Visualization API

I have a web app that data is submitted from a Ui embedded in a Google Site and saved in a spreadsheet. I am thinking about switching to scriptDB instead, but I am unsure about querying and displaying data dynamically. The last time I checked it was not possible to refresh a sites page from within a script, so as a work around I wrote a .html page with javascript that accesses the spreadsheet via the key and uses the Visualization DataTables to produce a quick and nicely formatted query. I would like to retain this functionality if possible. Could anyone make some possible suggestions?
Regards,
Shawn
This is doable today via UiApp (see the Charts api, and note that you can add a Chart to a UiApp).
To auto refresh:
You can use CheckBox.setValue(value, fireEvents) - but you may hit quota issues (there is an example somewhere around). If you hit quota issues, then I suspect HTML service is your best option. It also gives you better control.
Here is an open item requesting expanded Charts service integration with Gviz.
Although, there is limited integration at present, it needs to be expanded to group variables in tables to facilitate basic count and sum operations.
I suggest you “star” the issue to vote for it and to be notified of new developments.

How WappWolf gets notifications from Google Drive?

As far as I know there's no way for server-side application to be notified by Google Drive that some file has been updated or uploaded.
But it seems the WappWolf somehow gets it, via some API - how it does that? ( see introduction video http://wappwolf.com/gdriveautomator )
There is no way to currently get notifications from Google Drive. The best way is to poll the changes feed of the Documents List API to see if a user's Drive files have changed, which files have changed, and to act upon those changes accordingly.
There is a way, to get notification from GoogleDrive, only when in Spreadsheet Format.
But it's a good start.
In the spreadsheet, go to Tools > Notification Rule. Here, set the rule that will notify your email when any changes is made to the form + data + spreadsheet,(whatever we called it).
From this starting point, you may define how you are going to be notified. For me, the simplest would be gmail apps notification within my android phone. The sky's truly the limit.