4

Currently I am writing a simple API on Firebase Messaging. My code looks like this-

CODE

@Path("/f/n")
public class Notify {
    public static final Logger logger = Logger.getLogger(Notify.class);
    @Path("/m")
    @Produces("application/json")
    @GET
    public String sendMessageMbl(@Context ServletContext context, @Context HttpServletRequest request, @Context HttpHeaders httpHeaders) throws Exception{

        String response1 = "shreya";
        response1=FCM(response1);
        return response1;

    }

    public String FCM(String response1){
        try {

            String credential_file = PropertiesConstant.GOOGLE_SERVICES_JSON;
            FileInputStream serviceAccount = new FileInputStream(credential_file);
            FirebaseOptions options = new FirebaseOptions.Builder().setCredentials(GoogleCredentials.fromStream(serviceAccount)).build();

            try {
                FirebaseApp.initializeApp(options);
            }
            catch(Exception e){
                logger.error(e);
            }

            // This registration token comes from the client FCM SDKs.

            String registrationToken = "XYZ";

            Message message = Message.builder()
                    .putData("score", "850")
                    .putData("time", "2:45")
                    .setToken(registrationToken)
                    .build();
            response1 = FirebaseMessaging.getInstance().sendAsync(message).get();

        }catch(Exception e){
            logger.error(e);
        }

        return response1;
    }

}

ERROR MESSAGE

java.util.concurrent.ExecutionException: com.google.firebase.messaging.FirebaseMessagingException: Request contains an invalid argument.

REQUEST

GET http://localhost:8080/rest/f/n/m

REFERNCE

https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_individual_devices

shreya
  • 159
  • 2
  • 4
  • 14

0 Answers0