Skip to content

Firebase Cloud Messaging (FCM) Access Token Issue #917

@mostafamahmoud2015

Description

@mostafamahmoud2015

Hello,

i'm trying to send message via Firebase Cloud Messaging but i received the below error so can you please help in fixing this issue

java.util.concurrent.ExecutionException: com.google.firebase.messaging.FirebaseMessagingException: Error while calling FCM backend service
..

Caused by: java.io.IOException: Error getting access token for service account: connect timed out

code snippets :-
FileInputStream serviceAccount =
new FileInputStream("serviceAccountKey.json");

			FirebaseOptions options = new FirebaseOptions.Builder()
			  .setCredentials(GoogleCredentials.fromStream(serviceAccount))
			  .setDatabaseUrl("https://testnf-42343.firebaseio.com")
			  .build();

	FirebaseApp defaultApp =FirebaseApp.initializeApp(options);
	System.err.println(defaultApp.getName());
	
	UUID uuid = UUID.randomUUID();

	String registrationToken = FirebaseAuth.getInstance().createCustomToken(uuid.toString());


	// See documentation on defining a message payload.
	Message message = Message.builder()
	    .putData("score", "850")
	    .putData("time", "2:45")
	    .setToken(registrationToken)
	    .build();

	// Send a message to the device corresponding to the provided
	// registration token.
	FirebaseMessaging instance = FirebaseMessaging.getInstance();
	String response;
	try {
		response = instance.sendAsync(message).get();

// response = instance.send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);
} catch (Exception e) {
e.printStackTrace();
}

Metadata

Metadata

Assignees

Labels

needs more infoThis issue needs more information from the customer to proceed.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions