Submit data to Google Spreadsheet form from Objective-C

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

Maybe I could write the Http POST stuff, but I was wondering if someone had done this already, which I can use.

This question is similar to the iOS equivalent of this question for Android.

+5
source share
5 answers

based on @ Saad Farooq's answer, I actually tried to write 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];






}

. URL- .. @Saad . , , . SO, .

+10

Google Spreadsheet Forms blogged

HTTP POST iOS .

+4

, Swift. : https://github.com/goktugyil/QorumLogs

: https://github.com/goktugyil/QorumLogs/blob/master/Log%20To%20GoogleDocs.md

:

private static var googleFormLink: String!
private static var googleFormAppVersionField: String!
private static var googleFormUserInfoField: String!
private static var googleFormMethodInfoField: String!
private static var googleFormErrorTextField: String!

/// Setup Google Form links
static func setupOnlineLogs(#formLink: String, versionField: String, userInfoField: String, methodInfoField: String, textField: String) {
    googleFormLink = formLink
    googleFormAppVersionField = versionField
    googleFormUserInfoField = userInfoField
    googleFormMethodInfoField = methodInfoField
    googleFormErrorTextField = textField
}

private static func sendError(#text: String) {
    var url = NSURL(string: googleFormLink)
    var postData = googleFormAppVersionField + "=" + text
    postData += "&" + googleFormUserInfoField + "=" + "anothertext"                
    postData += "&" + googleFormMethodInfoField + "=" + "anothertext" 
    postData += "&" + googleFormErrorTextField + "=" + "anothertext" 

    var request = NSMutableURLRequest(URL: url!)
    request.HTTPMethod = "POST"
    request.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type")
    request.HTTPBody = postData.dataUsingEncoding(NSUTF8StringEncoding)
    var connection = NSURLConnection(request: request, delegate: nil, startImmediately: true)
}
+3

( ),

fbzx draftResponse pageHistory ( , "", -

NSString *authValue = [NSString stringWithFormat:@"Bearer %@", yourAccessTokenGottenFromGTMOAuth];
[request setValue:authValue forHTTPHeaderField:@"Authorization"]; 

, , ,

cocoapods

pod 'GTMOAuth2', '~> 1.1.2'
pod 'GTMSessionFetcher', '~> 1.1'

auth, OSX ( cocoapod GTMOAuth2)

HTTP GET form html ( NSScanner - ) , fbzx draftResponse .

, , google auth, , :

draftResponse = stringGottenFromHTMLGETAndParse & entry.someNumber = SomeValue & fbzx = stringGottenFromHTMLGETAndParse2 & = stringGottenFromHTMLGETAndParse3 & pageHistory = stringGottenFromHTMLGETAndParse4 & = stringGottenFromHTMLGETAndParse5

GTMOAuth2 HTTP- , , draftResponse .

I needed to add hidden inputs such as fbzx for HTTP POST in order to work when I had the option included in the form to automatically send email to users using the form.

0
source

All Articles