Showing posts with label google sheet. Show all posts
Showing posts with label google sheet. Show all posts

Tuesday, May 31, 2016

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

In the previous post we saw how we could extract various identifiers from the Google Form.  We will use these identifiers from the iOS app to do HTTP POST and submit information to the Google Form.

How to do HTTP POST to Google Form from iOS App

This is by far the simplest step of all.  We will be using the open source iOS library AFNetworking for doing the actual POST.
  • We first need to build a dictionary of all the POST parameters we want to submit to Google Forms using the identifiers extracted in the previous post
  • Then we need to set proper request and response serializers
  • We need to set the content type as "text/html".  Thats because Google Form will return HTML response
  • And finally we need to make the actual POST call.  AFNetwork accepts success and failure callbacks will will be called depending on whether the call succeeded or failed.
Once this is setup, test it out, on successful POST the data should be getting written to the backing Google Sheet.

Thats all folks.  We have concluded our three part series of how to write to Google Sheet from an iOS App!

Friday, April 29, 2016

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

In the previous post we saw how we could setup the Google Form to write to Google Sheet.

We will need 2 additional steps to submit information to Google Form from iOS app.

  • Extract the various identifiers (like URL, field id etc) of Google Form
  • Use the identifiers in the iOS app to do an HTTP POST to Google Form
In this post we will focus on the first step only.


Extract Identifiers From Google Form

  • All we need to do is click on the "Preview" button on our google form page.


  • It should open up our form as below


  • Right click on the form and say "Inspect".


  • If you are using Chrome brows, it should open up a panel below the page which looks something like this


  • Find a tag called "<form>" in the panel, there you should look for "action" attribute.  This attribute has a big URL as its value.  Save this URL we will to POST to this URL from our iOS app.


  • Next, Right click on the input field in your form and click "Inspect".  It should show "input" tag highlighted in the panel below.


  • We are not really interested in the input tag that the panel is showing, 
  • We need to find another input tag which is of 'type="hidden"'.  This input tag would be 8-9 lines below the input tag currently highlighted


  • Note down the value of "name" attribute on the input.  Do the same thing for other fields in the Google Form.  These keys will be used when we submit information from our iOS app to this form.

Once we have these identifiers noted we are left with one last step i.e. to do the HTTP POST from iOS app to Google Forms.  We will see how to do that in the next post.

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!