从Objective-C向Google Spreadsheet Form提交数据

是否有可用于使用表单向Google电子表格提交数据的图书馆,博客post等?

我大概可以写出HTTP POST的东西,但我想知道是否有人已经这样做了,我可以利用。

这个问题就像Android的这个问题的iOS相当于。

基于@Saad Farooq的回答,我确实试过编写代码

- (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]; } 

它实际上工作。 你需要从@ Saad的教程中提取url等。 顺便说一句,我是谁试图发布,以前的链接。 非常感谢通知他的SO工作人员。

我发现提交数据的Google Spreadsheet Forms方法在这里更容易和博客

iOS的一个简单的HTTP POST将会照顾它。

有gdata-objectivec-client 。 他们有一些在这里使用电子表格的示例代码。

我使用Swift完成了这个任务。 看看这个回购: https : //github.com/goktugyil/QorumLogs

这里是如何设置它的教程: https : //github.com/goktugyil/QorumLogs/blob/master/Log%20To%20GoogleDocs.md

inheritance人的代码做到这一点:

 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) } 

对于限制某些电子邮件地址并自动发送用户名(电子邮件地址)的工作,则需要提交表单中的隐藏字段

fbzx fvv draftResponse pageHistory标记(这不是访问标记,它是一个隐藏的inputforms,称为“标记”,使用类似于

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

在限制某些电子邮件的情况下执行您需要的访问令牌

使用椰子树

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

根据OSX示例显示的auth(包含在GTMOAuth2的cocoapod中)

您必须首先获取表单html,然后parsing它(使用NSScanner是parsing它的一个好方法),以获得隐藏的input字段,如fbzx和draftResponse和token。

然后,当你有这个,你的访问令牌从谷歌身份validation得到你做一个post看起来像这样:

draftResponse = stringGottenFromHTMLGETAndParse&entry.someNumber = someValue中&fbzx = stringGottenFromHTMLGETAndParse2&通气量= stringGottenFromHTMLGETAndParse3&pageHistory = stringGottenFromHTMLGETAndParse4&标记= stringGottenFromHTMLGETAndParse5

我需要为HTTP Post的GTMOAuth2工作,当提交者限制在表单中的某些电子邮件地址,但不需要隐藏的input,如draftResponse和令牌。

我需要添加隐藏的input,例如fbzx,以便HTTP POST可以在表单上启用选项时自动提交用户电子邮件。