Is there any way to write text into an existing shared Google Document, or to create a new google file in a shared Google folder, using Java (and without connecting to any account, as documents and folders are shared) ?
Thanks !
*EDIT
Rather than using the Google API, I created a Google Form which is filled by the application and which is exported to a Google Sheet automatically. I'm able to do a "POST" Http request OR to open the pre-filled Google form :
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();}
But I was wondering if there is a limit for the length of the URL, when I open it with "Desktop" and when I do a POST request ?
Thanks!