在尝试将数据发布到Google表格时,我正在
Content-Type application/x-www-form-urlencoded is not a valid input type.
我在终端
上尝试此命令curl -X POST -d '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended"><gsx:First>first name</gsx:First><gsx:Last>last name</gsx:Last></entry>' https://spreadsheets.google.com/feeds/list/0ArtbScpxn-LHdFQxQzJ3dDN2bEx2REFhYmo3UUxWUWc/od6/public/basic
答案 0 :(得分:2)
这是一个老问题,但我想我会继续提交我的发现。以下curl命令发布到我的测试谷歌表单。
curl -S -v -X POST --location https://docs.google.com/forms/d/1kqn-xxJeVL4ftczABTIHjonhlf9YUOUlMpsxzFT8Fok/formResponse \
-d entry.1915510022=curl \
-d entry.1382424262=ChriChri \
-d entry.1376741077=chriRoro%40um.com \
-d entry.1604030572=UM
-d entry.561632175=743-555%2B6321 \
-d entry.655897781=Yetassisi \
-d entry.227031813=coment+comanet \
-d entry.345486329=Yes
据我所知,您需要设置--location,-X POST,并使用-d条目添加表单数据。我发现最简单的方法是将Chrome开发工具打开到网络标签,然后使用普通表单进行测试提交。然后你可以看到-d条目和URL --location。注意。我添加了反斜杠并返回但是在OSX上,这些将需要在终端
中的命令工作中删除答案 1 :(得分:1)
来源:http://exhibita.com/blog/post/2009/09/10/Using-Google-Spreadsheets-to-Collect-Form-Data.aspx
1: //In order to post to Google Spreadsheet Form
2: //http://spreadsheets.google.com/formResponse?formkey=dFdYSTlzUVJsSomeReallyLongKeyGoesHereqemU2YUE6MA..
3: //Name "entry.0.single"
4: //Email is "entry.1.single"
5: //Phone is "entry.2.single"
6: //Comment is "entry.3.single"
7: //IP address is "entry.4.single"
8: $url = 'http://spreadsheets.google.com/formResponse?formkey=dFdYSTlzUVJsSomeReallyLongKeyGoesHereqemU2YUE6MA..';
9: // Create post array to send results to Google Spreadsheets
10: $fields = array(
11: 'entry.0.single'=>urlencode($name),
12: 'entry.1.single'=>urlencode($email),
13: 'entry.2.single'=>urlencode($phone),
14: 'entry.3.single'=>urlencode($comments),
15: 'entry.4.single'=>getRealIpAddr(),
16: 'submit'=>'submit'
17: );
18:
19: // Begining of code for posting to Google Spreadsheet
20: $fields_string = '';
21: //url-ify the data for the POST
22: foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
23: //rtrim($fields_string,"& ");
24: $fields_string = substr($fields_string, 0, strlen($fields_string)-1);
25: $result = "Fields_String: [" . $fields_string . "]<br />";
26:
27: //set POST variables for Google Spreadsheets
28: //open connection
29: $ch = curl_init();
30:
31: //set the url, number of POST vars, POST data
32: curl_setopt($ch,CURLOPT_URL,$url);
33: curl_setopt($ch,CURLOPT_POST,count($fields));
34: curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
35: curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
36: curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
37:
38: //execute post
39: $result .= "Curl Results: [" . curl_exec($ch) . "]<br />";
40:
41: //close connection
42: curl_close($ch);
当然这是使用php和curl,我认为从终端做起来不应该太难。 只需我0.02美元。