Firebase Admin SDK Java: serviceAccount.json not read

559 views
Skip to first unread message

Vincent Bott

unread,
Aug 19, 2018, 2:39:56 AM8/19/18
to Firebase Google Group
I'm trying to configure the Firebase Admin SDK on my Java app. It seems to me that the project_id, client_id and other credentials, is not being entered into the FirebaseOptions.
When I print out the project id, it says it is null, but I don't know what I'm doing wrong.

This is my code:

try {
   
FileInputStream serviceAccount = new FileInputStream("D:/Documenten/Prive/Projecten/DeLijnNotificatieProject/sample.test/src/main/resources/serviceAccountKey.json");

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

   
System.out.println("project_id: " + options.getProjectId());

   
FirebaseApp.initializeApp(options);

} catch (IOException e){
   
System.out.println("Probleem bij het laden van serviceaccount");
   
System.out.println(e.getMessage());
   
System.exit(1);
}
Geef de code hier op...

Setting up the Realtime Database on my android app, has been successful.

Can someone tell me what I've done wrong?

Hiranya Jayathilaka

unread,
Aug 20, 2018, 1:53:36 PM8/20/18
to fireba...@googlegroups.com
FirebaseOptions.getProjectId() only returns a value if the projectId was set via FirebaseOptions.Builder.setProjectId(). This is mentioned in the API docs: https://firebase.google.com/docs/reference/admin/java/reference/com/google/firebase/FirebaseOptions.html#getProjectId()

Internally, the SDK can access the project_id field of the service account json when it needs to. If you want to access, you should parse the service account json in your code.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/e84fb067-8220-46e5-8cc8-ed8fce223f6c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Hiranya Jayathilaka | Software Engineer | h...@google.com | 650-203-0128

Reply all
Reply to author
Forward
0 new messages