我正在尝试使用 Java 应用程序中的 token 将消息发送到单个设备。我正在使用 Firebase 管理 SDK。以下是我所拥有的
FileInputStream serviceAccount = null;
try {
serviceAccount = new FileInputStream("google-services.json");
} catch (FileNotFoundException e2) {
e2.printStackTrace();
}
FirebaseOptions options = null;
try {
options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://MYPROJECTID.firebaseio.com/")
.build();
} catch (IOException e1) {
e1.printStackTrace();
}
FirebaseApp.initializeApp(options);
String registrationToken = "MYDEVICETOKEN";
// See documentation on defining a message payload.
Message message = Message.builder().putData("time", "2:45").setToken(registrationToken)
.build();
// Send a message to the device corresponding to the provided
// registration token.
String response = null;
try {
response = FirebaseMessaging.getInstance().sendAsync(message).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);
但是我得到以下异常
java.io.IOException: Error reading credentials from stream, 'type' field not specified.
我在这里做错了什么?
最佳答案
关于java - 使用 Firebase 云和 Java 向单个设备发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49533855/