使用 python 中的请求将通知推送到 FireBase 时出现 InvalidRegistration 错误

时间:2021-05-19 13:50:10

标签: python firebase

嗨,我想向 firebase 推送通知

这是我的代码但是 当我运行时,输出是这个错误:

{'multicast_id': 4490969061378326571, 'success': 0, 'failure': 1, 'canonical_ids': 0, 'results': [{'error': 'InvalidRegistration'}]}

为什么?我怎样才能解决这个问题?有什么问题?!

import requests
import json

serverToken = 'your server key here'
deviceToken = 'device token here'

headers = {
        'Content-Type': 'application/json',
        'Authorization': 'key=' + serverToken,
      }

body = {
          'notification': {'title': 'Sending push form python script',
                            'body': 'New Message'
                            },
          'to':
              deviceToken,
          'priority': 'high',
        #   'data': dataPayLoad,
        }
response = requests.post("https://fcm.googleapis.com/fcm/send",headers = headers, data=json.dumps(body))
print(response.status_code)

print(response.json())

0 个答案:

没有答案