用于FCM的Twisted Python客户端-Firebase云消息(Android和iOS)……

txFCM的Python项目详细描述


versionlicense

用于FCM的Twisted Python客户端-FireBase云消息(Android&IOS)

firebase云消息(fcm)是gcm的新版本。它继承了可靠和可扩展的gcm基础设施,以及新功能。强烈建议GCM用户升级到FCM。

使用fcm,您可以通知客户端应用程序可以同步新电子邮件或其他数据。您可以发送通知来驱动用户重新登录和保留。对于即时消息之类的用例,消息可以将高达4KB的负载传输到客户端应用程序。

有关详细信息,请访问:https://firebase.google.com/docs/cloud-messaging/

快速启动

使用pip安装:

pip install txfcm

OR

pip install git+https://github.com/linteltechnologies/txfcm.git

txfcm支持android和ios。

功能

  • 涵盖所有FCM功能

示例

使用TXFCMNotification类发送通知:

# Send to single device.fromtxfcmimportTXFCMNotificationfromtwisted.internetimportreactorpush_service=TXFCMNotification(api_key="<api-key>")# Your api-key can be gotten from:  https://console.firebase.google.com/project/<project-name>/settings/cloudmessagingregistration_id="<device registration_id>"message_title="Uber update"message_body="Hi john, your customized news for today is ready"result=push_service.notify_single_device(registration_id=registration_id,message_title=message_title,message_body=message_body)# Send to multiple devices by passing a list of ids.registration_ids=["<device registration_id 1>","<device registration_id 2>",...]message_title="Uber update"message_body="Hope you're having fun this weekend, don't forget to check today's news"df=push_service.notify_multiple_devices(registration_ids=registration_ids,message_title=message_title,message_body=message_body)defgot_result(result):printresultdf.addBoth(got_result)reactor.run()

发送数据消息。

# With FCM, you can send two types of messages to clients:# 1. Notification messages, sometimes thought of as "display messages."# 2. Data messages, which are handled by the client app.# Client app is responsible for processing data messages. Data messages have only custom key-value pairs. (Python dict)# Data messages let developers send up to 4KB of custom key-value pairs.# Sending a notification with data message payloaddata_message={"Nick":"Mario","body":"great match!","Room":"PortugalVSDenmark"}# To multiple devicesresult=push_service.notify_multiple_devices(registration_ids=registration_ids,message_body=message_body,data_message=data_message)# To a single deviceresult=push_service.notify_single_device(registration_id=registration_id,message_body=message_body,data_message=data_message)# Sending a data message only payload, do NOT include message_body# To multiple devicesresult=push_service.notify_multiple_devices(registration_ids=registration_ids,data_message=data_message)# To a single deviceresult=push_service.notify_single_device(registration_id=registration_id,data_message=data_message)# Use notification messages when you want FCM to handle displaying a notification on your app's behalf.# Use data messages when you just want to process the messages only in your app.# txfcm can send a message including both notification and data payloads.# In such cases, FCM handles displaying the notification payload, and the client app handles the data payload.

发送低优先级消息。

# The default is low_priority == Falseresult=push_service.notify_multiple_devices(registration_ids=registration_ids,message_body=message,low_priority=True)

向主题发送消息。

# Send a message to devices subscribed to a topic.result=push_service.notify_topic_subscribers(topic_name="news",message_body=message)# Conditional topic messagingtopic_condition="'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)"result=push_service.notify_topic_subscribers(message_body=message,condition=topic_condition)# FCM first evaluates any conditions in parentheses, and then evaluates the expression from left to right.# In the above expression, a user subscribed to any single topic does not receive the message. Likewise,# a user who does not subscribe to TopicA does not receive the message. These combinations do receive it:# TopicA and TopicB# TopicA and TopicC# Conditions for topics support two operators per expression, and parentheses are supported.# For more information, check: https://firebase.google.com/docs/cloud-messaging/topic-messaging

其他参数选项

collapse_key (str, optional): Identifier for a group of messages
    that can be collapsed so that only the last message gets sent
    when delivery can be resumed. Defaults to `None`.
delay_while_idle (bool, optional): If `True` indicates that the
    message should not be sent until the device becomes active.
time_to_live (int, optional): How long (in seconds) the message
    should be kept in FCM storage if the device is offline. The
    maximum time to live supported is 4 weeks. Defaults to ``None``
    which uses the FCM default of 4 weeks.
low_priority (boolean, optional): Whether to send notification with
    the low priority flag. Defaults to `False`.
restricted_package_name (str, optional): Package name of the
    application where the registration IDs must match in order to
    receive the message. Defaults to `None`.
dry_run (bool, optional): If `True` no message will be sent but
    request will be tested.

访问响应数据。

# Response from FCM Server.response['multicast_id']#Unique ID (number) identifying the multicast message.response['success']#Number of messages that were processed without an error.response['failure']#Number of messages that could not be processed.response['canonical_ids']#Number of results that contain a canonical registration token.response['results']#Array of objects representing the status of the messages processed.result=[{responsedict},...]# The response objects are listed in the same order as the request (i.e., for each registration ID in the request,# its response is listed in the same index in the response).# message_id: String specifying a unique ID for each successfully processed message.# registration_id: Optional string specifying the canonical registration token for the client app that the message# was processed and sent to. Sender should use this value as the registration token for future requests. Otherwise,# the messages might be rejected.# error: String specifying the error that occurred when processing the message for the recipient

许可证

麻省理工学院的执照。

Copyright (c) 2016 Lintel Technologies Pvt Ltd ( http://lintel.in )

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

学分

大部分代码来自pyfcm,少量代码来自opera软件的twisted gcmclient代码。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何上传文件。HTML/Javascript格式的mp3文件并发送到Java后端   eclipse问题:使用Selenium WebDriver(java)从下拉列表中查找元素   java如何通过通知恢复应用程序   java Repast聚合数据集,但在Repast Simphony中分别针对每个实例   java为什么收到Http/1.1400错误请求?   java如何简单地检查请求体是否为空或请求体是否有空字段?   java JTable:如何避免重复行和聚合项目数量   java如何部署和访问Dropwizard应用程序   java找不到基本类weblogic。部署者   JavaSpringWebMVC互动程序从相同的定义扩展而来   javascript Xsl transformToDocument不适用于chrome浏览器,但适用于firefox   java创建存储泛型类型对象的ArrayList数组   如何在Java中禁用抛出异常或fillInStackTrace()   使用ConstraintValidator使用两种类型进行java自定义bean验证   java组织。百里香。例外情况。TemplateProcessingException:连接href