Skip to content

Firebase Cloud Messaging (FCM) Access Token Issue #917

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();
}

Activity

  1. added
    type: questionRequest for information or clarification. Not an issue.
    and removed
    triage meI really want to be triaged.
    on Dec 17, 2019
  2. codyoss commented on Dec 17, 2019

    @codyoss
    Member

    To me this sounds like a firewall issue with the timeout. Can you run curl -I "https://oauth2.googleapis.com/token" from where ever your code is running?

  3. added
    needs more infoThis issue needs more information from the customer to proceed.
    on Dec 17, 2019
  4. mostafamahmoud2015 commented on Dec 18, 2019

    @mostafamahmoud2015
    Author
  5. codyoss commented on Jan 2, 2020

    @codyoss
    Member

    Yes that is correct, although Firebase does have its own auth as well: https://firebase.google.com/docs/auth Are you still having issues?

  6. mostafamahmoud2015 commented on Jan 3, 2020

    @mostafamahmoud2015
    Author
  7. willian-kaminski commented on Apr 2, 2020

    @willian-kaminski

    hy guys!

    I'm trying to notify my app using the FCM but when i send the request i'm surprised by an exception.

    My send code:

    `
    try{

            Message message = Message.builder()
                    .putData("test", "test")
                    .putData("test", "test")
                    //.setToken("dla3GnhWQjc:APA91bH3dE2St0dLPMmhhTThgrpYSx7yY7gkR7sx_xL8DcQcDiCla_DtoJrhG-_uJFn9pmdwm78-0UcHIwJz1oplOb7n-P2n3FZY2vh1d1YP_Nirtt7NLVbQgDObQyLNwLQ0fr1JBEA6")
                    .setTopic(topic)
                    .build();
    
            // Send a message to the device corresponding to the provided
            // registration token.
            String response = FirebaseMessaging.getInstance().send(message);
            // Response is a message ID string.
            System.out.println("Successfully sent message: " + response);
    
        }catch (FirebaseMessagingException e) {
            System.out.println(e.getMessage());
        }
    

    `

    Excepiton:

    java.io.IOException: Error getting access token for service account:
    Error while calling FCM backend service

    can you help me?

  8. willian-kaminski commented on Apr 2, 2020

    @willian-kaminski

    I've already checked the credentials and firewall issue

  9. codyoss commented on Apr 2, 2020

    @codyoss
    Member

    Please open a new issue as this is a different exception.

  10. SanketNikam18062000 commented on Dec 8, 2022

    @SanketNikam18062000

    I've already checked the credentials and firewall issue

    hy guys!

    I'm trying to notify my app using the FCM but when i send the request i'm surprised by an exception.

    My send code:

    ` try{

            Message message = Message.builder()
                    .putData("test", "test")
                    .putData("test", "test")
                    //.setToken("dla3GnhWQjc:APA91bH3dE2St0dLPMmhhTThgrpYSx7yY7gkR7sx_xL8DcQcDiCla_DtoJrhG-_uJFn9pmdwm78-0UcHIwJz1oplOb7n-P2n3FZY2vh1d1YP_Nirtt7NLVbQgDObQyLNwLQ0fr1JBEA6")
                    .setTopic(topic)
                    .build();
    
            // Send a message to the device corresponding to the provided
            // registration token.
            String response = FirebaseMessaging.getInstance().send(message);
            // Response is a message ID string.
            System.out.println("Successfully sent message: " + response);
    
        }catch (FirebaseMessagingException e) {
            System.out.println(e.getMessage());
        }
    

    `

    Excepiton:

    java.io.IOException: Error getting access token for service account: Error while calling FCM backend service

    can you help me?

    have you got solution?
    bz I am getting also same error.

  11. neewaz commented on Nov 30, 2023

    @neewaz

    it was firewall issue , thanks alot
    …
    On Fri, Jan 3, 2020 at 1:38 AM Cody Oss @.***> wrote: Yes that is correct, although Firebase does have its own auth as well: https://firebase.google.com/docs/auth Are you still having issues? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#917?email_source=notifications&email_token=AD5HJ57TG5ZO64XTSK67E7TQ3ZUFHA5CNFSM4J3GZ27KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH7VKDA#issuecomment-570381580>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5HJ57YDLTJRHO5DYVOV3TQ3ZUFHANCNFSM4J3GZ27A .

    Hi, I am having the similar issue. What did you change in the firewall to make it work? Is there any list of IP-Addresses to be whitelisted?

  12. dineshsraman commented on Jan 31, 2024

    @dineshsraman

    Is there any list of IP-Addresses to

    Was this sorted? We too have a some issue in Firebase Messaging. Error seems to be different, but we are stuck in getting the access token and network team is analyzing the issue.

    Error : Error obtaining access token: Error getting access token for service account: Remote host terminated the handshake,iss.

  13. anish-anantharaman commented on Jan 8, 2025

    @anish-anantharaman

    @dineshsraman @neewaz @SanketNikam18062000 @codyoss
    I am also facing this same issue, any idea regarding this will be very helpful..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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