FCM在APP Server中创建TOPIC
FCM TOPIC Creation in APP Server
最近我从 GCM 迁移到 FCM 以通过我的应用程序发送通知,我想知道是否可以从我的应用程序服务器订阅特定主题的成员。如果可能,那么如何确定特定成员令牌是否有效或过期。
因为在我的数据库中,我有将近 22L 人的 GCM 注册令牌 ID,所以我将创建一个主题并通过我的应用服务器订阅这些成员。
解决此类问题的任何想法。
您可以使用 Instance ID API,特别是使用 batchAdd
,通过您的应用服务器为主题订阅多个令牌。它还可以通过返回 NOT_FOUND
错误来确定您 订阅 的注册令牌是否无效。来自文档:
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"},
{},
]
}
最近我从 GCM 迁移到 FCM 以通过我的应用程序发送通知,我想知道是否可以从我的应用程序服务器订阅特定主题的成员。如果可能,那么如何确定特定成员令牌是否有效或过期。
因为在我的数据库中,我有将近 22L 人的 GCM 注册令牌 ID,所以我将创建一个主题并通过我的应用服务器订阅这些成员。
解决此类问题的任何想法。
您可以使用 Instance ID API,特别是使用 batchAdd
,通过您的应用服务器为主题订阅多个令牌。它还可以通过返回 NOT_FOUND
错误来确定您 订阅 的注册令牌是否无效。来自文档:
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"}, {}, ] }