Closed BaljitKarwal closed 9 months ago
I found solution for this, using below code of line before calling AccessToken(); googleCredentials.refreshIfExpired(); and removed googleCredentials.refreshAccessToken();
I found solution for this, using below code of line before calling AccessToken(); googleCredentials.refreshIfExpired(); and removed googleCredentials.refreshAccessToken();
I just changed below and its worked
googleCredentials.refreshIfExpired();
//googleCredentials.refreshAccessToken();
Thank you @BaljitKarwal
I found solution for this, using below code of line before calling AccessToken(); googleCredentials.refreshIfExpired(); and removed googleCredentials.refreshAccessToken();
It works. thanks.
I'm also using similar code, but its throwing error. Any help?
Code: private static String getAccessToken() throws IOException { String[] SCOPES = {"https://www.googleapis.com/auth/firebase.messaging"};
GoogleCredentials googleCredentials = GoogleCredentials.fromStream(new FileInputStream("./src/service-account.json")).createScoped(Arrays.asList(SCOPES));
//googleCredentials.refresh();
try {
googleCredentials.getAuthenticationType();
googleCredentials.refreshIfExpired();
} catch (IOException e) {
e.printStackTrace();
}
return googleCredentials.getAccessToken().getTokenValue();
}
Error from refreshIfExpired call: Error getting access token for service account: Remote host terminated the handshake, iss: firebase-adminsdk-jnf15@*****
I'm also using similar code, but its throwing error. Any help?
Code: private static String getAccessToken() throws IOException { String[] SCOPES = {"https://www.googleapis.com/auth/firebase.messaging"};
GoogleCredentials googleCredentials = GoogleCredentials.fromStream(new FileInputStream("./src/service-account.json")).createScoped(Arrays.asList(SCOPES)); //googleCredentials.refresh(); try { googleCredentials.getAuthenticationType(); googleCredentials.refreshIfExpired(); } catch (IOException e) { e.printStackTrace(); } return googleCredentials.getAccessToken().getTokenValue(); }
Error from refreshIfExpired call: Error getting access token for service account: Remote host terminated the handshake, iss: firebase-adminsdk-jnf15@*****
I would suggest checking your JAVA_HOME and TLS versions.
I found solution for this, using below code of line before calling AccessToken(); googleCredentials.refreshIfExpired(); and removed googleCredentials.refreshAccessToken();
It's worked for me. Thank u
I am new to firebase however I did setup service account in console and used "messaging.java". Downloaded proper json file and updated all required variables in file.
I am getting this error now for getting access token from GoogleCredentials. I am unable to figure out what am I missing. Is it any variable misisng in my credentials file? or scope?
java.lang.NullPointerException at Messaging.getAccessToken
Can someone please advise? Below is my code:
` private static final String PROJECT_ID = "";
private static final String BASE_URL = "https://fcm.googleapis.com";
private static final String FCM_SEND_ENDPOINT = "/v1/projects/" + PROJECT_ID + "/messages:send";
private static final String MESSAGING_SCOPE = "https://www.googleapis.com/auth/firebase.messaging"; private static final String[] SCOPES = { MESSAGING_SCOPE };
private static final String TITLE = "FCM Notification"; private static final String BODY = "Notification from FCM"; public static final String MESSAGE_KEY = "message"; public static final String FIREBASE_SERVICE_PATH = "firebase_service_account/google-services.json";
/**
Regards Baljit