Firebase Messaging Device Groups

Viewed 116

The FCM documentation says that one should use device groups to send to ALL of a user's devices. The API for it, though, is still a legacy API, and I can't get it to work.

I am using code like the following, where project_id is the sender ID and api_key is the Web API Key from the firebase console:

In [9]: headers = {
   ...: 'Accept': 'application/json',
   ...: 'Authorization': f'key={api_key}',
   ...: 'project_id': str(project_id),
   ...: 'Content-Type': 'application/json',
   ...: }

In [10]: response = requests.get('https://fcm.googleapis.com/fcm/notification?notification_key_name=foo-foo', headers=headers)

In [11]: response.status
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-f75033194368> in <module>
----> 1 response.status

AttributeError: 'Response' object has no attribute 'status'

In [12]: response.content
Out[12]: b'<HTML>\n<HEAD>\n<TITLE>Internal Server Error</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Internal Server Error</H1>\n<H2>Error 500</H2>\n</BODY>\n</HTML>\n'

In [13]: response.reason
Out[13]: 'Internal Server Error'

In [14]: 
1 Answers

Ok, the "key" is the "server key" from the cloud messaging tab, and the "project_id" is the "Sender ID" from the same.

That seems to have solved it for me.

Related