erstellen Ich verwende Google Mail APIs zum ersten Mal. Ich versuche, einen Entwurf einer Nachricht mit Gmail API zu speichern. Der Quellcode ist ähnlich wie folgtkann keinen Entwurf mit gmail api
String urlLink = "https://www.googleapis.com/upload/gmail/v1/users/" + emailSetting.getEmailId() + "/drafts?uploadType=media";
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(urlLink);
httpPost.setHeader("Content-Type", "message/rfc822");
httpPost.setHeader("Authorization", "Bearer " + access_token);
StringEntity params = new StringEntity(message.toString());
httpPost.setEntity(params);
CloseableHttpResponse httpResponse = httpClient.execute(httpPost);
Hierher Nachricht wird die JSONObject, die ich die Meldung json der Vorbereitung bin mit wie folgt
JSONObject jsonObject = new JSONObject();
JSONObject message =new JSONObject();
jsonObject.put("threadId", 001);
jsonObject.put("snippet", msg.getSubject());
// Prepare Header start
JSONArray jsonArray = new JSONArray();
JSONObject jsonObj = new JSONObject();
jsonObj.put("name", "Delivered-To");
jsonObj.put("value", msg.getTo());
jsonArray.put(jsonObj);
jsonObj = new JSONObject();
jsonObj.put("name", "To");
//jsonObj.put("value", "<"+msg.getTo()+">");
jsonObj.put("value", msg.getTo());
jsonArray.put(jsonObj);
jsonObj = new JSONObject();
jsonObj.put("name", "From");
jsonObj.put("value", emailSetting.getEmailId());
jsonArray.put(jsonObj);
jsonObj = new JSONObject();
jsonObj.put("name", "Subject");
jsonObj.put("value", msg.getSubject());
jsonArray.put(jsonObj);
jsonObj = new JSONObject();
jsonObj.put("name", "Date");
jsonObj.put("value", new java.util.Date());
jsonArray.put(jsonObj);
JSONObject headerJSONObject = new JSONObject();
headerJSONObject.put("headers", jsonArray);
jsonObject.put("payload", headerJSONObject);
message.put("message", jsonObject);
message.put("id", msg.getMessageId());
Der obige Code mit dem Status ausgeführt wird 200. Aber der Entwurf der Botschaft ist leer, dh es gibt kein Subjekt, kein "zu" und keinen Körper. Wenn jemand einen Vorschlag zu diesem Quellcode hat, dann bitte teilen, danke.