Не удается отправить Firebase Cloud Messaging с помощью axios - PullRequest
1 голос
/ 11 марта 2020

Хотел разработать веб-уведомление на Firebase Cloud Messaging. Я использую axios для запроса, но, похоже, он не работает. Возникает ошибка:

Error: Request failed with status code 400

Код:

 componentDidMount() {
    const notifications = {
      notification: [
        {
          title: "Hola!",
          body: "Hello World",
          icon: "https://xxxx.com/icon.png",
          click_action: `https://example.com/`
        }
      ],
      to: token
     };
    axios
      .post(
        "https://fcm.googleapis.com/fcm/send",
        {
          notifications
        },
        {
          headers: {
            "Content-Type": "application/json",
            Authorization:
              "key=<FCM_SERVER_KEY>"
          }
        }
      )
      .then(response => {
        console.log("response" + response);
      })
      .catch(error => {
        console.log(error);
      });
...