是否有任何方法可以使用Java将文本写入现有的共享Google文档,或在共享的Google文件夹中创建新的google文件(并且无需共享任何帐户,因为文档和文件夹是共享的?)
谢谢!
* EDIT
不是创建Google表单,而是使用应用程序填充了Google表单,然后将其自动导出到Google表格中,而不是使用Google API。我可以执行“ POST” Http请求,也可以打开预先填写的Google表单:
try{URL url = new URL(my_google_form_direct_url);
//PREPARE PARAMS
Map<String,Object> params = new LinkedHashMap<>();
params.put("entry." + id_1, "TEXT1");
params.put("entry." + id_2, "TEXT2");
StringBuilder postData = new StringBuilder();
for(Map.Entry<String,Object> param : params.entrySet()){
if(postData.length() != 0){postData.append('&');}
postData.append(URLEncoder.encode(param.getKey(), StandardCharsets.UTF_8.name()));
postData.append('=');
postData.append(URLEncoder.encode(String.valueOf(param.getValue()), StandardCharsets.UTF_8.name()));}
byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8.name());
/************************************/
//SEND POST
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
conn.setDoOutput(true);
conn.getOutputStream().write(postDataBytes);
//GET RESPONSE
int response = conn.getResponseCode();
if(response == HttpURLConnection.HTTP_OK) {
Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8.name()));
InputStream in = conn.getInputStream();
in.close();}
conn.disconnect();
/************************************/
//OR OPEN THE PRE-FILLED FORM
URL prefilled_url = new URL(my_google_form_user_url + "?usp=pp_url&" + postData);
if(Desktop.isDesktopSupported()){
Desktop.getDesktop().browse(prefilled_url.toURI());}
}catch (IOException e1){e1.printStackTrace();}
但是我想知道URL的长度是否有限制,当我使用“ Desktop”打开它以及执行POST请求时,URL的长度是否受到限制?
谢谢!
https://github.com/stepio/jgforms
可能的限制主要是由HTTP标准定义的,所以这个问题可能会对您有所帮助:
What is the maximum length of a URL in different browsers?
根据我的经验,我成功地使用表格为Android应用程序实现了“记录器”:记录了完整的堆栈跟踪记录以及说明性消息。