5

是否有库、博客文章等可用于使用 Forms 将数据提交到 Google 电子表格?

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

这个问题就像 Android 的这个问题的 iOS 等价物。

4

5 回答 5

11

基于@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 工作人员。

于 2014-05-25T23:13:27.260 回答
4

我发现提交数据的 Google 电子表格表单方法要容易得多,并在此处写了博客

然后,来自 iOS 的一个简单的 HTTP POST 会处理它。

于 2012-10-09T07:54:33.707 回答
3

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

于 2012-09-16T19:49:51.400 回答
3

我使用 Swift 完成了这项任务。在这个 repo 中查看: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)
}
于 2015-09-17T10:16:40.290 回答
0

要使其限制某些电子邮件地址并自动发送用户名(电子邮件地址),您需要在表单中提交隐藏字段

fbzx fvv draftResponse pageHistory 令牌(这不是访问令牌,它是一种名为“令牌”的隐藏输入,使用类似

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

在仅限于某些电子邮件时执行您需要的访问令牌

使用可可足类

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

按照 OSX 示例所示执行身份验证(包含在 GTMOAuth2 的 cocoapod 中)

您必须首先 HTTP GET 表单 html 并解析它(使用 NSScanner 是解析它的好方法)以获取隐藏的输入字段,例如 fbzx 和 draftResponse 和 token。

然后,当您拥有它并从 google auth 获得访问令牌时,您会发布一个类似于以下内容的帖子:

DraftResponse=stringGottenFromHTMLGETAndParse&entry.someNumber=someValue&fbzx=stringGottenFromHTMLGETAndParse2&fvv=stringGottenFromHTMLGETAndParse3&pageHistory=stringGottenFromHTMLGETAndParse4&token=stringGottenFromHTMLGETAndParse5

当将提交者限制在表单中的某些电子邮件地址时,我需要为 HTTP Post 执行 GTMOAuth2,但不需要隐藏的输入,例如 DraftResponse 和令牌。

当我在表单上启用选项以自动使用表单提交用户电子邮件时,我需要添加隐藏的输入(例如 fbzx)以使 HTTP POST 工作。

于 2016-09-23T16:48:58.587 回答