Thursday, March 31, 2016

How to write to Google Sheet from an iOS app - Part 1

Recently we wanted to write some information to Google Sheet from our iOS app Monster Math.

There does exist an Objective C library that could directly write to the Google Sheet, but the API it exposes did look cumbersome.  What we did instead was a very simple hack.

  • We setup a Google Form with all the information we wanted to write to the Google Sheet.  
  • We then configured Google Form to write the responses to a Google Sheet.
  • This enabled us to directly submit information to Google Form using HTTP POST and responses will get written to Google Sheet automatically!
In this series I will explain how we could do the above steps.

Creating the Google Form

This is gonna be the super easy part.  
  • Login with you google account here
  • Click the big Plus icon to add a new form
  • Set the title as "My Survey".  If you want you can also add optional form description.

  • Next its time to setup questions which will act as columns in your Google Sheet
  • Lets setup two questions "Name" and "Age".
  • Enter "Name" in the text field that reads "Question"
  • Change the type of the Question from "Multiple Choice" to "Short Answer"

  • Similarly add one more question with title "Age" and of type "Short Answer".
  • After the setup your from should look like the image below.

Our Google Form is ready for use.  Now we just need to link it with a Google Sheet so that our responses get written there.

Link Google Form with a backing Google Sheet
  • Click on the "Responses" tab.
  • There you should see a green Google Sheet icon, click that.

  • It should prompt you to create a new Google Sheet with name "My Survey (Responses)", create it.

  • This should open up a Google Sheet which looks something like the image below.

Verification

Thats about it, you have successfully setup Google Forms to write its responses to Google Sheet.  You can verify the setup by clicking the preview icon on the Google Form.



It should open up the form which should look like the image below



Go ahead and submit some dummy information to test the setup.  This information should be written to the Google Sheet automatically.



Congratulation on reaching this far, the configuration part is over.  All we need to do is hook up this form from iOS app, we will cover that in the next post. 
Have some Fun!