kat*_*ter 2 python api python-3.x firebase firebase-cloud-messaging
我正在尝试通过新的 FCM api 协议实现发送通知。我经历了身份验证请求,我也在谷歌控制台中启用了 api。现在,当我发送请求时,我收到错误请求 400 错误。除了错误代码和错误消息外,响应不包含任何其他信息。甚至原因字段显示“错误请求”。我正在使用FCM api docs实现它。
def fcm_test():
FCM_URL = "https://fcm.googleapis.com/v1/projects/MY_PROJECT_NAME/messages:send"
my_token = "device-token"
payload = {
"massage": {
"token": my_token,
"notification": {
"body": "body",
"title": "title"
}
}
}
payload = json.dumps(payload)
headers = {
"Authorization": "Bearer {auth_token}".format(auth_token=_get_authentication_token()),
"Content-Type": "application/json; UTF-8",
}
try:
request = moves.urllib.request.Request(FCM_URL, payload.encode('utf-8'), headers)
response = moves.urllib.request.urlopen(request, timeout=10)
except Exception as e:
pass
return
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2675 次 |
| 最近记录: |