Is there a way to allow users to access Google Sheets without manually signing in? - authentication

I have set up a Google Apps Script that validates data that is entered into various Google Sheets files. I am looking for a way to allow users to access those Google Sheets files without making them sign in manually.
There are various onEdit() triggers set up that monitor these Sheets files and apply formatting to cells when data input errors occur. I'm doing validation with Google Apps Scripts because the errors are determined through non-straightforward business logic which makes Sheets' built-in data validation insufficient. The triggers are set up by a standalone Google Apps Script project. This setup means I cannot simply share a link to the Google Sheets file and have people edit it anonymously and have the data checked and cells formatted, because the scripts require more permissions than are necessary for anonymous editing.
I've looked briefly at some Google Auth API docs, but I'm not a security or web dev by trade so it's a bit confusing.
I'm looking for a solution where the user could click on a link to a Sheets file and automatically be redirected to the Sheets file and be signed in to a Google account that is managed by me, and which already has permission to access that Sheets file (this way they won't be editing these files with their personal accounts). The link would be on a Drupal site that users would have already signed into using Drupal's built-in sign-in functionality, in case that makes a difference.

You can write a stand-alone script and build a trigger yourself:
ScriptApp.newTrigger('Edit')
.forSpreadsheet('THE_SPREADSHEET_ID')
.onEdit()
.create();
function Edit()
{
//does not necessary need to be the same spreadsheet
SpreadsheetApp.openById('THE_SPREADSHEET_ID').getActiveSheet().getRange('A20').setValue('it worked');
}
If you set the sharing permission for the spreadsheet to "Anyone with the link can edit", every user (including anonymous) editing the spreadsheet will cause the trigger to run. Just make sure that after writing the script you run it once manually, after this it will run automatically on every edit.

Related

How to get the currently selected cell/range with the Google Sheets API?

Same question as this one, but when using the Google API, not Google Apps Script. I use Java but an illustration in any language or REST would be good.
Answer:
You cannot do that, since the spreadsheet itself doesn't have a selected range. A certain user may have selected a range, but that information is not available to the API (see spreadsheet resource for further reference).
Explanation:
In Apps Script, bound scripts get the special privilege of using methods (e.g. getActiveRange()) that provide information on what the current user has selected (see Special methods).
But even using Apps Script, this cannot work in standalone scripts. Let alone using the API.

Could I have a user to write/read data to/from a google spreadsheet of *his* from a static website?

I could not store any secret keys since the data would be accessed though a static website. (I dont want to use google forms)
I understand I need a secret api key if I want anyone to write/read data to/from a google spreadsheet that is mine, but this is not my case.
This for example about a simple "TODO app", where each user would just access their own data, do I still need a key if each user is accessing only their own private spreadsheed?
This is kind of a broad question so my answer would be a series of recommendations, in that way you will have a better idea of what you have to do to fulfill your goal:
1) First of all. If you haven't heard about Apps Script, I would recommend you to check it, because it integrates easily programming tools for all Google apps.
2) Now knowing what's Apps Script, you could check how to integrate Apps Script code into your Spreadsheet by Extending Google Sheets.
3) Spreadsheet Service allows performing several tasks related to your Sheet files.
4) Knowing about Apps Script and how to handle the Sheets files by coding, the next step will be to check Web Apps, which will help you to create an integrated web app on your Spreadsheet.
5) The last thing I recommend you is to see the Class google.script.run (Client-side API), this class will pass values from your Front-end to your Back-end built on Apps Script.

How to automate sending credentials to a DRM server to open a DRM pdf?

I have a client who wants me to automate certain document processing work.
There is this pdf that can only be opened by sending in username and password to a DRM server.
When I open it using Acrobat, I see this.
I have the username and password, courtesy of the client.
Issue is how do I automate this?
I have done web scraping before, where I automate a web login so that I can execute certain routine tasks.
But this is the first time I am trying to automate an authentication that does not occur inside the browser.
How do I go about doing this?
Companies pay a lot of money to do exactly not this. http://www.adobe.com/devnet/reader/topic_drm.html. I suspect the amount of effort to do this will not be worth it, especially if you are going to try and dive into the actual protocols/plugins used and hook in directly. This would be very implementations specific and likely to break in the future.
Your best bet is to leverage the existing Adobe Application and wrap it in an Automator script. Unfortunately, OSX specific.
They won't have generic workflow hooks, so the quick and nasty way would be to just record yourself doing it once, and play it back time and time again.
Workflow:
Drag PDF onto custom app
Automatically populate username
Automatically populate password
If you are looking for somewhere to start: http://www.macosxautomation.com/automator/features/virtual-user.html
The DRM module itself can set permissions about how you can print and re-distribute the files itself, you won't be able to get around any of that, but assuming you have all the permissions set correctly, you should at least be able to automate opening the file itself on OSX.

office 365 api generate a guest link for MyFiles

I am trying to access from an MVC application, the OneDrive files from my office 365 account.
What I need is to give my application user the possibility to edit a .docx file, in their browser.
I used Office 365 APIs Preview, to get the list of files, and their properties, but I don't know how to allow the user to edit that file in his browser.
A solution to this problem could be to share the file with different user of my application, by creating a guest link.
From the office365 portal this is a simple task:
- OneDrive, select the file -> manage -> share with -> get a link, the link can have read only or read write rights.
I don’t know how to create this link from the APIs.
Can you please tell me how can I generate this guest link or if there is a different solution to this problem.
In short, I don't think this can be done in a supported way.
There is a real risk that if you figure out the URL structure, that the structure could change. I suggest that you make a feature request by using UserVoice. It would be preferable that the REST API and the client objects construct this URL for you.
With that said, if you take the sharing link, and place it into a browser window, the link will redirect to Word Online with the document in the browser. Take a look at the structure of the URL in the Word Online browser window. You could use that as a template, and along with the information from the File.Url property from the Office 365 API Preview, you may be able to put together a URL to that file. Expect that this approach would not be supported and would be subject to URL structure changes.
If other people find that this would be a useful feature, please use UserVoice to let us know.

Can you create Google Forms from Google Docs in an application?

I am thinking about app that will use google form and I need to create forms from that app. Is there a way how can I create form in google docs without using website but through some api or some other way?
I can offer an idea for a solution using Google App Script.
Since the beginning of 2013 you can create new forms using the App Script Forms Service API quite easily.
var form = FormApp.create(title)
.setDescription(description)
.setConfirmationMessage('Thanks for responding!')
;
The problem now is how to get that App Script running from your non App Script code.
You can use App Script to create a Web App that reacts to HTTP GET requests.
So putting it together, you may be able to create an App Script Web App that reacts to a GET request and when it gets the right URL parameters, it creates the form.
(Nov 2020) Yes, it is possible to programmatically create Google Forms. You can do it with Google Apps Script using its Forms service. You can also extend the code to read in the contents from Google Docs (with Apps Script's Document service) and use it for the creation of Google Forms.
I created a Google Workspace (formerly G Suite) Add-on, which you can think of as a Google Docs extension, called GFormIt. Its original purpose was intended for teachers to write exams/quizzes, possibly with answers, in Google Docs, then automatically convert them to Google Forms to distribute to students who submit their answers into Google Sheets (the destination for Google Forms submissions).
Furthermore, if you (the teacher) provided answers to your test questions, GFormIt would also auto-submit your answers to the Sheet as if you were a student. If you do that, and use a tool like Flubaroo to grade the exam, you could designate your row in the Sheet as “the answer key.” You can learn more about how it works, including viewing a short video, at the GFormIt page linked above.
This Google Docs add-on, along with others for Google Docs, Sheets, Slides, Forms, etc., are all certified/validated by Google and available for free to anyone from the Google Workspace Marketplace. (However, your admins may have to grant permissions for you to try to install them to your corporate Workspace account.) If interested in building your own add-on, please see the developer documentation and perhaps some of my introductory videos to get started, the most relevant being the one linked to at the top of this answer.
Apps Script is a serverless Google technology, meaning you write your code (using JavaScript) in the browser, and it is hosted by & executed on Google servers. If you wanted to create your own web app (and hosted anywhere), you would have to wait for a Google Forms REST API which does not exist at the time of this writing. (If we ever launch one, you'll find its documentation at https://developers.google.com/forms along with the others like Sheets https://developers.google.com/sheets, Gmail https://developers.google.com/gmail, Drive https://developers.google.com/drive, etc.)
Earlier this year (Mar 2022) the new Google Forms Api graduated from Beta. It is more powerful that the previous versions and caters for two main use cases:
Automated form creation and editing: Enables automated form creation
and editing. Enables rapid form generation from large volume question
banks or other data backends.
Reaction to Form responses: The API also enables developers to build
automations for acting on incoming responses. Examples include
developing real-time dashboards or visualizations and triggering
business workflows based on response data.
We have used it to build an integration that Creates documents and slides each time a form is completed: www.portant.co/google-forms-to-docs and it works really well.
I think the other key use case looks like it would be a good fit for you and others looking for a solution like this.
Cheers, James
Sorry, the API doesn't support programmatically creating forms.