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 Bad Request{错误": {代码":400,"message": "请求包含无效参数.",错误":[{"message": "请求包含无效参数.",域":全球",原因":错误请求"}],状态":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);
消息发送代码如下
// 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屋!