我尝试通过新的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
答案 0 :(得分:4)
您的有效负载密钥中有一个拼写错误,您可以使用" message"再次尝试而不是"按摩"?