2011-12-30 74 views
1

試圖發佈數據,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 

回答

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和捲曲,我認爲它不應該太難從終端做。 只需要我的$ 0.02。

+0

0123雖然我發現這個鏈接,但無法將其轉換... – coure2011 2011-12-30 19:38:09

+0

你卡在哪裏 – 2011-12-30 19:48:18

1

這是一個老問題,但我想我會繼續並提交我的發現。以下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 - 位置。注意。我添加了反斜槓並返回,但在OSX上這些將需要刪除的命令工作在終端