django-push-notifications
django-push-notifications copied to clipboard
push notification to topic throws
from the documentation here https://github.com/jazzband/django-push-notifications
from push_notifications.gcm import send_message
# First param is "None" because no Registration_id is needed, the message will be sent to all devices subscribed to the topic.
send_message(None, {"body": "Hello members of my_topic!"}, to="/topics/<my_topic>_here")
when I do as stated above, I get this error
send_message(None, {"body": "Hello members of my_topic!"},
TypeError: send_message() missing 1 required positional argument: 'cloud_type'
I look up the send_message function in site-packages, it is defined like this def send_message(registration_ids, data, cloud_type, application_id=None, **kwargs)
then I modify my arguments to send_message to contain my cloud_type and application_id thus:
send_message(None, {"body": "Hello members of my_topic!"}, cloud_type='FCM',
to="/topics/<my_topic_here>", application_id="my application id")
I then get this error
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/celery/app/trace.py", line 385, in trace_task
R = retval = fun(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/celery/app/trace.py", line 650, in __protected_call__
return self.run(*args, **kwargs)
File "/usr/src/app/competition/tasks.py", line 10, in pushnotification_to_topic
send_message(None, {"body": "Hello members of my_topic!"}, cloud_type='FCM',
File "/usr/local/lib/python3.8/site-packages/push_notifications/gcm.py", line 209, in send_message
return _cm_send_request(None, data, cloud_type=cloud_type, **kwargs)
File "/usr/local/lib/python3.8/site-packages/push_notifications/gcm.py", line 159, in _cm_send_request
response = json.loads(_fcm_send(
File "/usr/local/lib/python3.8/site-packages/push_notifications/gcm.py", line 60, in _fcm_send
key = get_manager().get_fcm_api_key(application_id)
File "/usr/local/lib/python3.8/site-packages/push_notifications/conf/app.py", line 312, in get_fcm_api_key
return self._get_application_settings(application_id, "FCM", "API_KEY")
File "/usr/local/lib/python3.8/site-packages/push_notifications/conf/app.py", line 274, in _get_application_settings
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: push_notifications.conf.AppConfig requires the application_id be specified at all times.
here is my settings:
PUSH_NOTIFICATIONS_SETTINGS = {
"CONFIG": "push_notifications.conf.AppConfig",
"APPLICATIONS": {
"<my application_id>": {
"PLATFORM": "FCM",
"API_KEY": <my api key>,
},
}
}
I encountered this issue. You have to fill out the application_id column in the push_notifications_gcm table in your database.
I did that. Did yours get solved with it?
Yes, it solved it for me. But I am sending only to a single user and not an entire topic.
Yes, it solved it for me. But I am sending only to a single user and not an entire topic.
I can send to a single and multiple devices via the device.send_message method and it works. It is only when I try to send to users subscribed to my topics (see the directive in the screenshot) that I get that error.
