如何使用Python通过Lambda通过Firebase发送推送通知 [英] How to send push notification via Lambda by Firebase using Python
本文介绍了如何使用Python通过Lambda通过Firebase发送推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过AWS Lambda从Firebase Cloud Message发送推送通知.该API会回应授权错误.
I am trying to send a push notification from Firebase Cloud Message via AWS Lambda. The API responds with authorization error.
导入请求 导入json
import requests import json
def lambda_handler(event, context):
message = event['Message']
tokens = event['PushNotificationTokens']
for token in tokens:
data = {"notification": { "title": "My Awesome App", "body": message,}, "to": token}
data_json = json.dumps(data)
print(data_json)
headers = {'Content-type': 'application/json', 'Authorization':'AAAA…...0HuQH'}
url = 'https://fcm.googleapis.com/fcm/send'
response = requests.post(url, data=data_json, headers=headers)
jsonResponse = json.loads(response.content)
print(jsonResponse)
return jsonResponse
推荐答案
除标题之外,所有内容都很完美.您必须在实际键之前添加"Key =".参见下面的代码:
Everything is perfect - except the headers. You'll have to add 'Key=' before the actual key. See the code below :
headers = {'Content-type': 'application/json', 'Authorization':'Key=AAAA…...0HuQH'}
这篇关于如何使用Python通过Lambda通过Firebase发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文