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.
- 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?
- Is there a simple "click through" tutorial how to deploy the node server code to the google environment?
Thanks to , and continuing on Frank's answer .. here's a few additional observations
1.
serviceAccountKey.json
is not the actual file nameComing 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.
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.
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.
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.
Have a look at this comment
https://stackoverflow.com/a/49039675/2472466
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.
The returned private key will be a .json file which will be your 'serviceAccountKey.json' file ... once you rename it to be 'serviceAccountKey.json'
the 'path/to/' is the directory where you store the returned json file, this directory must be within your firebase project