【问题标题】:Submit data to Google Spreadsheet Form from Objective-C从 Objective-C 向 Google 电子表格提交数据
【发布时间】:2012-09-10 19:13:54
【问题描述】:

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

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

这个问题类似于 iOS 的 this Android 问题。

【问题讨论】:

    标签: objective-c ios google-sheets


    【解决方案1】:

    根据@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 的教程here 中提取URL 等。顺便说一句,我是尝试发布以前链接的人。非常感谢通知他的 SO 工作人员。

    【讨论】:

    • 工作好伙伴!!我相信这会对人们更有帮助
    • 更新:有一个名为 Sheetsu(sheetsu.com) 的新服务正是这样做的。
    • @RobinThuranMalhotra....请提供如何编辑/修改/删除表格objective-c中的数据
    【解决方案2】:

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

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

    【讨论】:

    • 有人注意到此链接已损坏,也许您可​​以扩展它曾经包含的内容?
    • @TonyHopkinson 很抱歉。链接已更新为有效链接。感谢您指出了这一点。我觉得有太多数据无法回答,但如果您认为它可能合适,请随时发布编辑。
    • 不是我的伙伴,新的 SO 用户无法发表评论,因此他们试图编辑您的答案。
    • @SaadFarooq 感谢您的教程,我使用您的方法制作了一个日志记录实用程序:github.com/goktugyil/QorumLogs
    【解决方案3】:

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

    【讨论】:

      【解决方案4】:

      我使用 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)
      }
      

      【讨论】:

        【解决方案5】:

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

        fbzx fvv 响应草案 页面历史 令牌(这不是访问令牌,它是一种名为“令牌”的隐藏输入,使用类似

        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

        当将提交者限制在表单中的某些电子邮件地址时,我需要执行 GTMOAuth2 才能使 HTTP Post 工作,但不需要隐藏的输入,例如 draftResponse 和 token。

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

        【讨论】:

          猜你喜欢
          • 2011-09-11
          • 2017-11-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多