Server implementation is optional. Use the Instance ID service if you wantto perform these operations:
- Firebase Server Key
- How To Get Firebase Server Key
- Generate A Firebase Server Key Code
- Generate A Firebase Server Key For Free
How to generate server key for push notification in Android? After navigating to the project dashboard, click “Add Firebase to your Android App”. Nov 30, 2016 This blog gives you detail how to create Google API Key for Standard user. So, if you are using API under standard plan, then in a project of your choice the API Key set up needs to be done. Firebase Cloud Messaging (FCM) is used to deliver push notifications to Android devices, Google Chrome and Mozilla web browsers. Feb 14, 2020 Your app server or other trusted server environment where your server logic runs, such as Cloud Functions for Firebase or other cloud environments managed by Google. Your app server or trusted server environment sends message requests to the FCM backend, which then routes messages to client apps running on users' devices. You'll need to enable Cloud Firestore: In the Firebase console menu's Develop section, click Database. Click Create database in the Cloud Firestore pane. Select the Start in test mode option, then click Enable after reading the disclaimer about the security rules.
- Get information about app instances.Verify app tokens or get more information about the app instance that created the token.
- Create relationship maps for app instances. Create relationships between app instances and entities such as FCM or GCM topics.
- Create registration tokens for APNs tokens. This API lets you bulk importexisting APNs tokens, mapping them to valid registration tokens for FCM or GCM.
- Manage registration tokens for push subscriptions.For web applicationsimplemented using the Push API, import your existing push subscriptions, mappingthem to valid registration tokens for FCM.
Get information about app instances
To get information about an app instance, call the Instance ID service atthis endpoint, providing the app instance's token as shown:
Firebase Server Key
Parameters
Authorization
: key=YOUR_API_KEY. Set this parameter in the header.- [optional] boolean
details
: set this query parameter totrue
to get FCM orGCM topic subscription information (if any) associated with this token. When notspecified, defaults tofalse
.
Results
On success the call returns HTTP status 200 and a JSON object containing:
application
- package name associated with the token.authorizedEntity
- projectId authorized to send to the token.applicationVersion
- version of the application.appSigner
-sha1
fingerprint for the signature applied to the package.Indicates which party signed the app; for example,Play Store
.platform
- returnsANDROID
,IOS
, orCHROME
to indicate the deviceplatform to which the token belongs.
If the
details
flag is set:rel
- relations associated with the token. For example, a list of topicsubscriptions.
Example GET
request
Example result
Create relationship maps for app instances
The Instance ID API lets you create relationship maps for app instances.For example, you can map a registration token to a Google Cloud Messaging topic,subscribing the app instance to the topic. The API provides methods for creatingsuch relationships both individually, and in bulk.
Create a relation mapping for an app instance
Given a registration token and a supported relationship, you can createa mapping. How to generate ssh key. For example, you can subscribe an app instance to aGoogle Cloud Messaging topic by calling the Instance ID service atthis endpoint, providing the app instance's token as shown:
Parameters
Authorization
: key=YOUR_API_KEY. Set this parameter in the header.
Results
On success the call returns HTTP status 200.
Example POST
request
Example result
Manage relationship maps for multiple app instances
Using the Instance ID service's batch methods, you can perform batchmanagement of app instances. For example, you can perform bulkaddition or removal of app instances to an FCM or GCM topic.To update up to 1000 app instances per API call, call the Instance IDservice at this endpoint, providing the app instance tokens in the JSON body:
Parameters
Authorization
: key=YOUR_API_KEY. Set this parameter in the header.to
: The topic name.registration_tokens
: The array of IID tokens for the app instances you want to add or remove.
Results
On success the call returns HTTP status 200. Empty results indicate successfulsubscription for the token. For failed subscriptions, the result contains oneof these error codes:
- NOT_FOUND — The registration token has been deleted or the app has been uninstalled.
- INVALID_ARGUMENT — The registration token provided is not valid for the Sender ID.
- INTERNAL — The backend server failed for unknown reasons. Retry the request.
- TOO_MANY_TOPICS — Excessive number of topics per app instance.
Example POST
request
Example result
Create registration tokens for APNs tokens
Using the Instance ID service's
batchImport
method, you can bulk importexisting iOS APNs tokens to Google Cloud Messaging or Firebase Cloud Messaging,mapping themto valid registration tokens. Call the Instance ID service atthis endpoint, providing a list of APNs tokens in the JSON body: Generate a private key file.The response body contains an array of Instance ID registration tokens readyto be used for sending FCM or GCM messages to the corresponding APNs device token.
Note: The list of APNs tokens in each request cannot exceed 100.![Generate Generate](/uploads/1/3/3/9/133907255/876739463.png)
Parameters
Authorization
: key=YOUR_API_KEY. Set this parameter in the header.application
: Bundle id of the app.sandbox
: Boolean to indicate sandbox environment (TRUE) or production (FALSE)apns_tokens
: The array of APNs tokens for the app instances you want to add or remove. Maximum 100 tokens per request.
Results
On success the call returns HTTP status 200 and a JSON result body. For eachAPNs token provided in the request, the results list includes:
- The APNs token.
- Status. Either OK, or an error message describing the failure.
- For successful results, the registration token that FCM or GCM maps to the APNs token.
Example POST
request
Example result
Manage registration tokens for push subscriptions
Using the Instance ID service's Web methods, you can import existingpush subscriptions for Firebase Cloud Messaging. You can also update anddelete them.
When you import a push subscription, you receive a registration token.This token allows you to use FCM features like topic messaging anddevice group messaging to target notifications to your web apps.
Import push subscriptions
You can import push subscriptions using InstanceID's web endpoint:
The request must contain an authorization header set to an OAuth 2.0 access token, a crypto-key header set to your application server key, andthe
PushSubscription
object in the request body.The response body contains a registration token ready to be usedfor sending FCM or GCM messages to the corresponding web app instancewithout having to encrypt the payload.
Upload your VAPID key pair to the console
To import keys, you must have owner-level accessto the Firebase project. Import your existing public and private key inbase64 URL safe encoded form:
- Open the Cloud Messaging tab of the Firebase Console Settingspane and scroll to the Web configuration section.
- In the Web Push certificates tab, find and select the link text, 'import an existing key pair.'
- In the Import a key pair dialog, provide your public and private keys in the corresponding fields and click Import. The console displays the public key string and date added.
Retrieve an OAuth2 token: Use credentials to mint access tokens
In order to create an access token for the request, you'll need to mint the access token and add it to the HTTP request.
To authorize access to FCM, request the scope
https://www.googleapis.com/auth/firebase.messaging
.Parameters
- Authorization:
Bearer <access_token>
. Set this parameter in the header. - Crypto-Key:
p256ecdsa=APPLICATION_PUBLIC_KEY
. Set this parameter in the header. - Request body:
PushSubscription.toJson()
. Pass the push subscription to theHTTP body withoutparsing it. The content matches W3C encoding ofPushSubscription
.
Response
On success the call returns HTTP status 200 OK and a JSON result bodycontaining the IID token.
Example POST
request
Example result
Update push subscriptions
You can update the push subscription associated with your registration tokenusing the following endpoint:
Parameters
How To Get Firebase Server Key
- Authorization:
Bearer <access_token>
. Set this parameter in the header. - Crypto-Key:
p256ecdsa=APPLICATION_PUBLIC_KEY
. Set this parameter in the header. - Request body:
PushSubscription.toJson()
. Pass the push subscription to the HTTP body withoutparsing it. The content matches W3C encoding ofPushSubscription
.
Results
On success the call returns HTTP status 200 and a registration token. Thismay be the same token you passed in the request, or a new token.
Example POST
request
Example result
Delete push subscriptions
A
DELETE
request removes the push subscription details from FCM database. Youcan still receive messages in your web application using the Push API protocol.To delete a push subscription, send a
DELETE
request to:Example DELETE
request
Example result
Error responses
Generate A Firebase Server Key Code
Calls to the Instance ID server API returnthe following HTTP error codes:
Generate A Firebase Server Key For Free
HTTP status 400 (Bad request)
- request parameters are missing or invalid.Check error messages for detailed information.HTTP status 401 (Unauthorized)
- authorization header is invalid.HTTP status 403 (Forbidden)
- authorization header doesn't match theauthorizedEntity
.HTTP status 404 (Not found)
- Invalid HTTP path or IID token not found.Check error messages for detailed information.HTTP status 503 (Service unavailable)
- service is unavailable. Retry therequest with exponential backoff.