Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit data to Google Spreadsheet Form from Objective-C

Is there a library, blog post, etc. that can be used to submit data to a Google Spreadsheet using Forms ?

I could probably write up the Http POST stuff but I was wondering if someone had done so already that I can utilize.

This question is like the iOS equivalent of this question for Android.

like image 220
Saad Farooq Avatar asked Sep 10 '12 19:09

Saad Farooq


People also ask

Can Google Forms send data to Google Sheets?

That's great for quick form results, but for more tools to analyze answers, you can link your form to a Google Sheets spreadsheet. Just click the green Sheets icon in the Responses tab or click Select response destination in the menu, then create a new spreadsheet or select an existing one to store the answers.


1 Answers

based on @Saad Farooq's answer, I actually tried writing the code

- (void)viewDidLoad
{
    [super viewDidLoad];

    //if there is a connection going on just cancel it.
    [self.connection cancel];

    //initialize new mutable data
    NSMutableData *data = [[NSMutableData alloc] init];
    self.receivedData = data;

    //initialize url that is going to be fetched.
    NSURL *url = [NSURL URLWithString:@"https://docs.google.com/forms/d/1yffvViDKq7BHALtC7Om-ceFLWT5hb_cM9sBqndHG3aU/formResponse"];

    //initialize a request from url
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[url standardizedURL]];

    //set http method
    [request setHTTPMethod:@"POST"];
    //initialize a post data
    NSString *postData = @"entry.154268020=iOS&entry.940479455=vajhcsd&entry.247556683=BJKSVDB";
    //set request content type we MUST set this value.

    [request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

    //set post data of request
    [request setHTTPBody:[postData dataUsingEncoding:NSUTF8StringEncoding]];

    //initialize a connection from request
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    self.connection = connection;

    //start the connection
    [connection start];






}

and it actually works. You need to extract the URLs etc from @Saad's tutorial here. BTW, I was the one who tried posting that the previous links. A big thank you to the SO staff who informed him.

like image 113
Robin Thuran Malhotra Avatar answered Sep 18 '22 13:09

Robin Thuran Malhotra