1

I have fcm tokens in my database and for some tokens are used to send push notifications.

Everything is working fine as required. But there is optimization required since some device token I am getting

string(116)
"{
"multicast_id": 1234,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [{
  "error": "NotRegistered"
}]
}
"

Could any help me verify device token if registered already before sending push notification?

KENdi
  • 7,576
  • 2
  • 16
  • 31
Null Pointer
  • 458
  • 1
  • 4
  • 14
  • As far as I am aware, you can't tell prior to sending a push, but when you receive the response, parse it for failure and then remove from database as needed – Liam G Jun 07 '18 at 11:02

1 Answers1

3

You can verify if a token in your database is still valid or not using the Instance ID Server Reference GET API. If you got a response similar to below, it means that the token is still valid.

Example GET request:

https://iid.googleapis.com/iid/info/nKctODamlM4:CKrh_PC8kIb7O...clJONHoA?details=true
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

Example result

HTTP 200 OK
{
  "application":"com.iid.example",
  "authorizedEntity":"123456782354",
  "platform":"Android",
  "attestStatus":"ROOTED",
  "appSigner":"1a2bc3d4e5",
  "connectionType":"WIFI",
  "connectDate":"2015-05-12
  "rel":{
    "topics":{
      "topicname1":{"addDate":"2015-07-30"},
      "topicname2":{"addDate":"2015-07-30"},
      "topicname3":{"addDate":"2015-07-30"},
      "topicname4":{"addDate":"2015-07-30"}
    }
  }
}
looptheloop88
  • 3,026
  • 17
  • 20