2
votes

I'm trying to create a Java Application which should send a Protocol to the Firebase Cloud Messaging Servers. Now I have the problem, that I don't know how to see if my message was sent correctly. When I head to the Web-Console of Firebase/Notifications there is no message to see.

My Code (just in case):

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) {
    }
}
}

Output:

[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] org.apache.http.client.entity.DecompressingEntity@32cf48b7}

Thank you!

PS There is a reference of FCM https://firebase.google.com/docs/cloud-messaging/server

1
Hey I am also trying the same thing. Getting same responce as you.So now I am trying a different way to send it.If it succeeds i get success:1 kind of message. .. then i reply back. - Debasish Ghosh

1 Answers

0
votes

By "how to see if my message was sent correctly", I'm presuming you mean if it was sent towards the client app device.

For this scenario, you can make use of the Delivery Receipts. However, you'll have to implement an XMPP server, instead of the regular HTTP connection server.

One way to also have check is to make use of the Diagnostics tool, but a requirement for this to be available is for your app to be at least in Alpha Testing.


The only logs/details you can see in the Firebase Console are the messages sent using Firebase Console itself, it won't show any messages sent using the FCM REST API.


Else, if you are pertaining to just verify if the message was sent correctly towards the FCM servers, then you should check the response. Normally, it should return "success": 1 and a message_id.