にHTTPポストを送信します。 メッセージが正しく送信されたかどうかを知る方法がわからないという問題が発生しました。WebコンソールFirebase/Notificationsメッセージがありませんを参照してください。 (念のため)Firebaseクラウドメッセージングは、私が<strong>Firebaseクラウドメッセージング</strong>サーバーに<strong>プロトコル</strong>を送信する必要があります<strong>Javaアプリケーション</strong>を作成しようとしているJavaの
マイコード:
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.json.JSONObject;
public class Mainclass {
public static void main(String[] args) {
// Declaration of Message Parameters
String message_url = new String("https://fcm.googleapis.com/fcm/send");
String message_sender_id = new String("XXXX-XXXX");
String message_key = new String("key=XXXX-XXXX");
// Generating a JSONObject for the content of the message
JSONObject message = new JSONObject();
message.put("message", "TEXT");
JSONObject protocol = new JSONObject();
protocol.put("to", message_sender_id);
protocol.put("data", message);
// Send Protocol
try {
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost request = new HttpPost(message_url);
request.addHeader("content-type", "application/json");
request.addHeader("Authorization", message_key);
StringEntity params = new StringEntity(protocol.toString());
request.setEntity(params);
System.out.println(params);
HttpResponse response = httpClient.execute(request);
System.out.println(response.toString());
} catch (Exception e) {
}
}
}
出力:
[Content-Type: text/plain; charset=ISO-8859-1,Content-Length: 59,Chunked: false]
HttpResponseProxy{HTTP/1.1 200 OK [Content-Type: application/json; charset=UTF-8, Date: Mon, 26 Dec 2016 12:09:13 GMT, Expires: Mon, 26 Dec 2016 12:09:13 GMT, Cache-Control: private, max-age=0, X-Content-Type-Options: nosniff, X-Frame-Options: SAMEORIGIN, X-XSS-Protection: 1; mode=block, Server: GSE, Alt-Svc: quic=":443"; ma=2592000; v="35,34", Transfer-Encoding: chunked] [email protected]}
ありがとうございます! 「私のメッセージが正しく送信されたかどうかを確認する方法」により、FCM https://firebase.google.com/docs/cloud-messaging/server
私も同じことをやっています。あなたと同じ反応を得ています。今、私はそれを送るために別の方法を試みています。成功すれば成功します:1種類のメッセージ。 ..返信します。 – Debasish