如何使用Python通过Firebase通过lambda发送推送通知



我试图通过AWS Lambda从Firebase Cloud消息发送推送通知。API响应授权错误。

导入请求导入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

除了标题外,一切都是完美的。您必须在实际密钥之前添加"键="。请参阅下面的代码:

headers = {'Content-type': 'application/json', 'Authorization':'Key=AAAA…...0HuQH'}

相关内容

  • 没有找到相关文章

最新更新