0

Recently I migrated from GCM to FCM for sending the notification via my app, i want to know whether can able to subscribe the members in particular topic from my app server. If possible, then how will find out if a particular member token valid or expired.

Because in my database, i have near to 22L people GCM Registration TOKEN id, so that i will create one topic and subscribe those members via my app server.

Any ideas to resolve this kind of issues.

AL.
  • 36,815
  • 10
  • 142
  • 281
Saikumar
  • 877
  • 1
  • 9
  • 22
  • Currently what we are doing means, we are sending the notification by using register_id ( GCM Token Id ) individually, if will get the not registered error in gcm, then we will remove that entry from db. The same how will handle it if we are going to use the TOPIC concept. If any one of register id which has been subscibed that topic getting failed or getting the same error in internally. How will handle it? – Saikumar Mar 09 '17 at 11:43
  • How was it? Were you able to look into it? – AL. Mar 16 '17 at 03:43

1 Answers1

1

You can subscribe multiple tokens to Topic via your App Server using the Instance ID API, specifically, using batchAdd. It can also identify if the Registration Token that you were subscribing is invalid by returning a NOT_FOUND error. From the docs:

Manage relationship maps for multiple app instances

Using the Instance ID service's batch methods, you can perform batch management of app instances. For example, you can perform bulk addition or removal of app instances to an FCM or GCM topic. To manage app instances, call the Instance ID service at this endpoint, providing the app instance tokens in the JSON body:

https://iid.googleapis.com/iid/v1:batchAdd

https://iid.googleapis.com/iid/v1:batchRemove

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 successful subscription for the token. For failed subscriptions, the result contains one of 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

https://iid.googleapis.com/iid/v1:batchAdd
Content-Type:application/json
Authorization:key=API_KEY
{
   "to": "/topics/movies",
   "registration_tokens": ["nKctODamlM4:CKrh_PC8kIb7O...", "1uoasi24:9jsjwuw...", "798aywu:cba420..."],
}

Example result

HTTP 200 OK
{
  "results":[
    {},
    {"error":"NOT_FOUND"},
    {},
  ]
}
Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • What roles are required on service account for these apis? – Eugene S. Mar 25 '19 at 20:23
  • @EugeneS I'm not sure what you mean. The minimum role (iirc) is a view-access only role. If they can view the API Key, then they're pretty much good to go. – AL. Mar 26 '19 at 03:12
  • I'm using dotnet SDK and it uses service account (json with private key) to send the messages. When I try to use the same method on this api I get 401. So I was wondering if it's possible to call these apis without using Server Api Key, like with send. – Eugene S. Mar 27 '19 at 13:52
  • I haven't tried using the .net SDK before so I can't say for sure. But I do know that most (if not all) requests that is intended for FCM requires only the Server Key from it's intended project. – AL. Mar 27 '19 at 14:04