44

I managed to go through the complete Firebase Android Codelab without too much problem, the app works perfectly. Now I would like to add device-to-device notifications. I found this tutorial: And some things are not clear to me.

  1. In the node script there is a line like this:

var serviceAccount = require("path/to/serviceAccountKey.json");

What is the "ServiceAccountKey.json" file? Is it just another name for google-services.json? If not, what is this?

  1. Is there a simple "click through" tutorial how to deploy the node server code to the google environment?
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Entman
  • 637
  • 1
  • 6
  • 12
  • 1
    For #2 there is a link to the [running node.js on Google Cloud Platform](https://cloud.google.com/nodejs/) tutorial right in the blog post. Aside from that: "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Frank van Puffelen Jan 26 '17 at 13:25
  • 1
    Ooh! The man himself :) Yea, i saw that guide, i just thought somebody maybe knew a simpler, more "visual" tutorial, but this will easily do. Was thinking about whether i should ask the #2 question at all, turns out it's a faux pas, my bad ;P And as for #1? Aand you answered it too. You're the man ;p – Entman Jan 26 '17 at 13:29
  • One problem with two questions in one post is that #2 is off-topic. Your entire post might be closed as off-topic. Which would be a shame, because I just provided an answer for your first question. :-) – Frank van Puffelen Jan 26 '17 at 13:31

4 Answers4

21

In the blog post you're following, we're running the node.js script on Google Cloud's App Engine Flexible Environment using the Firebase Admin SDK. A service account is a way to give trusted processes access to Google Cloud Platform and Firebase resources.

You create a service account through the Google Cloud Console and then download the corresponding JSON file. The code in the blog post looks for that file and use it to initialize the Firebase Admin SDK.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
18

Thanks to , and continuing on Frank's answer .. here's a few additional observations

1. serviceAccountKey.json is not the actual file name

Coming from work on the Android client side, I thought that was a fixed name the way that google-services.json is in the Android project. However, it's just a place-holder name. The file is generated with a unique name from the Google Web UI, and that is the file to apply where the place-holder is referenced.


2. You can only get the file one time

Going through the docs there, I thought maybe you can use an existing service account to get that file. However, after some looking around .. I tried creating a new one and from the dialog it gives there, the checkbox tells us you can only get that .json file one time - at time Service Account item is created.

The docs discuss creating a Service Account, but I didn't see much mention otherwise of getting that .json file.. so that's why it seemed ambigious until I saw this dialog.

enter image description here


3. The screen where you add a new service account

That Admin UI has a lot going on, including from the docs a variety of references to go to IAM Setup, Roles, etc.

At the risk of stating the obvious (but may help someone else arrive here faster than I did), - this was the view where I add the Service Acct and get the dialog to download the .json file.

enter image description here

Gene Bo
  • 11,284
  • 8
  • 90
  • 137
14

Have a look at this comment

https://stackoverflow.com/a/49039675/2472466

  1. in a nutshell, you generate serviceAccountKey.json file by requesting a new private key from the service accounts tab of your settings page in your Firebase dashboard.

  2. The returned private key will be a .json file which will be your serviceAccountKey.json file ... once you rename it to be serviceAccountKey.json

  3. the path/to/ is the directory where you store the returned json file, this directory must be within your firebase project

TuGordoBello
  • 4,350
  • 9
  • 52
  • 78
t.ios
  • 1,024
  • 12
  • 18
  • 2
    Great answer! For #3, let's say I have the .JSON file stored in my raw folder in resources on my project. How would i call it from there? Or do you mean I need to put the .JSON file in storage on Firebase and call it from there? Thanks – Travis Whitten Dec 25 '18 at 16:24
  • Base for path appears to be from where the calling source file is located. – user3015682 Dec 10 '20 at 22:15
3

It's pretty confusing but firstly you'll have to generate a service account from Google IAM. Once you create the service account, right click on the three dots and select "create key". It should prompt you with JSON option. Download and store it within your project directory.

IVI
  • 1,893
  • 1
  • 16
  • 19