gpt4 book ai didi

python - FCM API 'Bad request 400' 错误

转载 作者:太空宇宙 更新时间:2023-11-04 08:33:48 24 4
gpt4 key购买 nike

我正在尝试通过新的 FCM api 协议(protocol)实现发送通知。我通过了身份验证请求,我也在谷歌控制台中启用了 api。现在,当我发送请求时,我收到 Bad request 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

最佳答案

您的有效载荷 key 中有一个拼写错误,您可以用“message”而不是“massage”再试一次吗?

关于python - FCM API 'Bad request 400' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50789210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com