Firebase
クラウドメッセージング管理者を使用してメッセージを送信しているときにエラーが発生しますAPI
。
エラーメッセージは以下のとおりです
原因:com.google.api.client.http.HttpResponseException:400 Bad Request {"error":{"code":400、 "message": "リクエストに無効な引数が含まれています。"、 "errors":[{"メッセージ ":"リクエストに無効な引数が含まれています。 "、"ドメイン ":"グローバル "、"理由 ":" badRequest "}]、"ステータス ":"無効_引数 "}}
ここに管理者設定を入れましょう。
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>
だから誰かがこれで私を助けることができますか?私は何が間違っているのですか?
あなたのregistrationToken
フォーマットが無効だと思います。152文字である必要があります。
これを確認するには、の代わりにsetTopic( "test")を使用してメッセージを作成してみてくださいsetToken(registrationToken)
。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加