curl将数据发布到google电子表格

curl将数据发布到google电子表格,curl,google-docs-api,Curl,Google Docs Api,当我试图将数据发布到谷歌工作表时,我发现 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:Fir

当我试图将数据发布到谷歌工作表时,我发现

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
curl-X POST-d'first name last name'https://spreadsheets.google.com/feeds/list/0ArtbScpxn-LHdFQxQzJ3dDN2bEx2REFhYmo3UUxWUWc/od6/public/basic
来源:

1://以便发布到谷歌电子表格
2: //http://spreadsheets.google.com/formResponse?formkey=dFdYSTlzUVJsSomeReallyLongKeyGoesHereqemU2YUE6MA..
3://Name“entry.0.single”
4://电子邮件为“entry.1.single”
5://电话是“进入2.单身”
6://注释为“entry.3.single”
7://IP地址为“entry.4.single”
8:$url=$http://spreadsheets.google.com/formResponse?formkey=dFdYSTlzUVJsSomeReallyLongKeyGoesHereqemU2YUE6MA..';
9://创建post数组以将结果发送到Google电子表格
10:$fields=array(
11:'entry.0.single'=>urlencode($name),
12:'条目.1.单个'=>urlencode($email),
13:'条目.2.单个'=>urlencode($phone),
14:'entry.3.single'=>urlencode($comments),
15:'entry.4.single'=>getRealIpAddr(),
16:“提交”=>“提交”
17:                 );
18:  
19://发布到谷歌电子表格的代码开始
20:$fields\u string='';
21://url为帖子提供数据
22:foreach($key=>$value的字段){$fields\u string.=$key.'='.$value.&';}
23://rtrim($fields_string,“&”);
24:$fields\u string=substr($fields\u string,0,strlen($fields\u string)-1);
25:$result=“Fields\u String:[”$Fields\u String.]
; 26: 27://为Google电子表格设置POST变量 28://开放连接 29:$ch=curl_init(); 30: 31://设置url、POST变量数、POST数据 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://executepost 39:$result.=“Curl Results:[”.Curl_exec($ch)。“]
”; 40: 41://密切联系 42:卷曲关闭($ch);
当然,这是使用php和curl,我认为从终端执行应该不会太困难。
只有我的0.02美元。

这是一个老问题,但我想我应该继续提交我的发现。下面的curl命令发布到我的测试google表单

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上,需要删除它们,以便在终端中执行命令

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