![](/img/trans.png)
[英]google cloud container registry error: "Failed to trigger build: Request contains an invalid argument."
[英]firebase cloud messaging Request contains an invalid argument
使用Firebase
云消息传递管理API
发送消息时出现错误。
错误信息如下
引起:com.google.api.client.http.HttpResponseException: 400 Bad Request { "error": { "code": 400, "message": "Request contains an invalid argument.", "errors": [ { " message": "Request contains an invalid argument.", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } }
让我把我的管理配置放在这里..
FileInputStream serviceAccount = new FileInputStream("My service accout file.json");
FirebaseOptions options = new FirebaseOptions.Builder().setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://deliveryeat-1aa42.firebaseio.com").build();
FirebaseApp.initializeApp(options);
消息发送代码如下
// This registration token comes from the client FCM SDKs.
String registrationToken = "YOUR_REGISTRATION_TOKEN";
// See documentation on defining a message payload.
Message message = Message.builder().putData("score", "850").putData("time", "2:45").setToken(registrationToken).build();
// Send a message to the device corresponding to the provided
// registration token.
String response = FirebaseMessaging.getInstance().sendAsync(message).get();
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);
我正在使用的 Maven 依赖项如下
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>5.9.0</version>
</dependency>
那么有人可以帮助我吗? 我究竟做错了什么?
另一个原因是您的消息太大:
通知消息可以包含可选的数据负载。 两种消息类型的最大负载均为 4KB,但从 Firebase 控制台发送消息时除外,它强制执行 1024 个字符的限制。
https://firebase.google.com/docs/cloud-messaging/concept-options
一个可能的原因是客户端和服务器连接到不同的 firebase 项目。 项目名称出现在客户端的 google-services.json 文件和服务器的凭据 json 中。
我怀疑您的registrationToken
格式无效。 它应该是 152 个字符。
要确认这一点,请尝试使用setTopic("test")而不是setToken(registrationToken)
构建您的消息。
就我而言,问题在于通知数据有效负载中不允许使用某些键。 具体来说,密钥“from”是被禁止的。
我在 URL 中将我的项目名称大写(奇怪,因为我的项目名称实际上是大写的)
我在尝试将“content_available”标志设置为 true 时收到此错误(这是文档所说的: https ://firebase.google.com/docs/cloud-messaging/http-server-ref )。
原来你需要它是“内容可用”的。
就我而言,问题出在Condition
部分。 我使用了无效字符。
例如错误: 03:00' in topics
尝试向 iOS 模拟器设备发送推送通知时也会发生此错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.