使用以前(旧)版本的 google 表单,可以通过将 HttpPost 发送到这样的 url 以编程方式将数据发布到表单:
https://spreadsheets.google.com/formResponse?formkey=[key]
和这样的数据:
entry.1.single=data&entry.2.single=moredata
随着新版本的谷歌表单(我认为 2013 年 1 月发布)的 url 结构不同。这是“查看实时表单页面”的片段
<form action="https://docs.google.com/forms/d/1Ee330GpkMHX_0dKWmJb6ZPdm4FBhhqJSqBbgysEtq6M/formResponse" method="POST" ...
<input type="text" name="entry.1566150510"
从这段代码片段中,我认为我可以发布到这样的网址:
https://docs.google.com/forms/d/[key]/formResponse
有这样的数据:
entry.1566150510=data
但我已经从 java(android) 尝试过这样的:
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
Log.i(myTag, "Inside postData()");
String fullUrl = "https://docs.google.com/forms/d/1Ee330GpkMHX_0dKWmJb6ZPdm4FBhhqJSqBbgysEtq6M/formResponse";
Log.i(myTag, "url = " + fullUrl);
HttpPost httppost = new HttpPost(urlBase);
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("entry.1566150510", "somedata"));
UrlEncodedFormEntity data = new UrlEncodedFormEntity(nameValuePairs);
Log.i(myTag, data.toString());
httppost.setEntity(data);
Log.i(myTag, EntityUtils.toString(data));
// Execute HTTP Post Request
ResponseHandler<String> responseHandler=new BasicResponseHandler();
String response = httpclient.execute(httppost, responseHandler);
Log.i("DocsUploader", "response = " + response);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我得到 404,没有找到响应。
我在这里遗漏了一些明显的东西,还是谷歌刚刚删除了发布到新表单的功能?