Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically create and manage Google Forms via Google Document List API

We have a very specific need. We want to create a generic (Java based) registration system for Event organizers. So every Event organizer can define a custom form on our application, and then we collect the data from users for that particular event.

Now the input fields can change from Event to Event, so I was thinking to use some out-of-box cloud solution. One obvious thing came to my mind was to use Google Forms. So for every event, if we can programmatically create a Google Form and get following 2 things: 1) Embed link for that form 2) Access to corresponding data keeping Google Spreadsheet

We can use the embed link to show the Registration form to users on Event page. And we can access the Google Spreadsheet to access the data that Users have been filling in the Registration form.

But when I searched for it, I couldn't get a clear way to achieve this. There is some Google Documents List API, through which you can create Google documents programmatically, but I couldn't figure out, how to meet our needs through this API.

It would be of great help, if somebody can guide us in this regard. Or suggest us any alternate cloud solution.

UPDATE:: Looks like Google doesn't provides an API at all for Forms linked with Spreadsheets. http://goo.gl/ia8rk If we are lucky, they might include in their future releases. So any other cloud based API that can be handy for this problem??

like image 414
sachinaero Avatar asked May 03 '13 10:05

sachinaero


1 Answers

If I understand correctly, you have a Google sheet and you want a way to automatically generate a form. That generated form should link its responses back to that spreadsheet. Is that correct?

I don't know a way to do that with Java (if there is an available API for that, I don't think so) but that can be easily accomplished with Google Scripts. This was built in the script editor of a Google Spreadsheet.

Here is an example:

function onOpen() {
  // read the docs to add to the toolbar
}

function getColumnHeaders() {
  // this grabs the headers of your sheet
  var headers = SpreadsheetApp
    .getActiveSheet()
    .getRange(1, 1, 1, SpreadsheetApp.getActiveSheet().getLastColumn())
    .getValues()[0];

  // this will appear in your root directory
  var newForm = FormApp.create('NEW FORM NAME');
  newForm.setDestination(FormApp.DestinationType.SPREADSHEET, SpreadsheetApp.getActiveSpreadsheet().getId());

  headers.forEach(function(each) {
    newForm.addTextItem().setTitle(each);
  });
}

The documentation can be found here: https://developers.google.com/apps-script/reference/forms/

like image 67
Jordan Rhea Avatar answered Sep 24 '22 09:09

Jordan Rhea