Reputation: 1
I am trying to send a push notification from Firebase Cloud Message via AWS Lambda. The API responds with authorization error.
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
Upvotes: 0
Views: 2646
Reputation: 14125
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'}
Upvotes: 3