在APP服务器中创建FCM主题 [英] FCM TOPIC Creation in APP Server

查看:343
本文介绍了在APP服务器中创建FCM主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我从GCM迁移到FCM通过我的应用程序发送通知,我想知道是否能够从我的应用程序服务器订阅特定主题的成员。如果可能的话,那么如何才能找出一个特定的成员令牌是否有效或过期。

因为在我的数据库中,我已经接近22L人GCM注册的TOKEN ID,所以我将创建一个主题,并通过我的应用程序服务器订阅这些成员。

任何想法来解决这种问题。

解决方案

您可以使用 Instance ID API ,特别是使用 batchAdd 。它也可以通过返回一个 NOT_FOUND 错误来识别你注册的令牌是否是无效的。从文档:


管理多个应用程序实例的关系图



使用实例ID服务的批处理方法,可以执行应用程序实例的批处理。例如,您可以批量添加或删除应用程序实例到FCM或GCM主题。要管理应用程序实例,请调用此端点上的Instance ID服务,并在JSON主体中提供应用程序实例标记:

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

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

参数


  • 授权:key = YOUR_API_KEY。
  • 转换为:主题名称。

  • registration_tokens:您要添加的应用程序实例的IID令牌数组或删除。


    结果
    $ b

    成功时,调用将返回HTTP状态200 。空结果表示令牌成功订阅。对于失败的订阅,结果包含以下错误代码之一:




    • NOT_FOUND - 注册令牌已被删除或应用程序已被卸载。
    • 重试请求。
    • TOO_MANY_TOPICS - 每个应用程序实例的主题数量过多。

      $ b 示例POST请求

        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 ...],
      }

      示例结果

        HTTP 200 OK 
      {
      results:[
      {} ,
      {error:NOT_FOUND},
      {},
      ]
      }



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.

解决方案

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"},
    {},
  ]
}

这篇关于在APP服务器中创建FCM主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆