firebase云消息传递请求包含无效参数 [英] firebase cloud messaging Request contains an invalid argument
问题描述
使用 Firebase
云消息管理 API
发送消息时发生错误。
I am getting error while sending message using Firebase
cloud messaging admin API
.
错误消息在下面
造成者:com.google.api.client.http.HttpResponseException:400错误请求
{
错误:{
code:400,
message:请求包含无效参数。,
errors :[
{
message:请求包含无效的参数。,
domain:global,
reason:badRequest
status:INVALID_ARGUMENT
}
}
Caused by: 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" } }
<
Let me put my admin configuration here..
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);
邮件发送代码
Message sending code is below
// 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依赖关系如下
maven dependencies that i am using is following
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>5.9.0</version>
</dependency>
那么有人能帮助我吗?我在做什么错了?
So can anyone help me in this? What am I doing wrong?
推荐答案
我怀疑你的 registrationToken
格式无效。它应该是152个字符。
I suspect that your registrationToken
has an invalid format. It should be 152 characters.
要确认这一点,请尝试使用 setTopic(test)而不是 setToken(registrationToken)
。
To confirm that, try building your message with setTopic("test") instead of setToken(registrationToken)
.
这篇关于firebase云消息传递请求包含无效参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!