FCM-未注册

Jac*_*ael 5 java firebase firebase-cloud-messaging

我正在尝试通过FCM向我的Web应用发送消息。不幸的是,我收到以下错误消息,我无法独自解决...

通过POSTMAN我收到了JSON:

 {
    "multicast_id": 7441926471010389687,
    "success": 0,
    "failure": 1,
    "canonical_ids": 0,
    "results": [
        {
            "error": "NotRegistered"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

这是我仅有的错误消息。请参阅我发送给FCM的以下POSTMAN配置POST消息在此处输入图片说明

在此处输入图片说明

有人已经面临过同样的问题吗?我找不到任何解决办法来解决我在互联网上的问题...

另请参见下面的Firebase.java

package com.inovans.backend.web.rest.firebase;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Service;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.Message;

@Service
public class Firebase {

    @PostConstruct
    void initialierMyFirebase() {
        this.initializeFirebase();
    }

    private void initializeFirebase() {

        // if(this.firebaseApp.getApps().isEmpty()) {

        FileInputStream serviceAccount = null;
        try {
            serviceAccount = new FileInputStream(
                    "src/main/java/com/inovans/backend/web/rest/firebase/emergency-manager-57773-firebase-adminsdk-x4p6o-c2ea07c8f4.json");
        } catch (FileNotFoundException e) {
            System.out.println(
                    "Impossible de récupérer le fichier JSON de configuration de FIREBASE. Le chemin n'est pas valide. "
                            + serviceAccount);
            e.printStackTrace();
        }

        FirebaseOptions options = null;
        try {
            options = new FirebaseOptions.Builder().setCredentials(GoogleCredentials.fromStream(serviceAccount))
                    .setDatabaseUrl("https://emergency-manager-57773.firebaseio.com").build();
        } catch (IOException e) {
            System.out.println("Impossible d'initialiser l'application FIREBASE : " + options);
            e.printStackTrace();
        }

        System.out.println("OPT : " + options);

        FirebaseApp.initializeApp(options);

        // }
    }

    public void sendMessage(String token) {

        // See documentation on defining a message payload.
        /*
        Message message = Message.builder()
                .setWebpushConfig(WebpushConfig.builder()
                        .setNotification(new WebpushNotification("$GOOG up 1.43% on the day",
                                "$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.",
                                "https://my-server/icon.png"))
                        .build())
                .setToken(
                        "fh4Jcwe3vhg:APA91bGvw6crsojSroBE31aeR32ZRjfJyCisHNUWiR6froP53c0YpQ7uG-EtkiPIQ0ZUnY2fYW_TF4T6NFhQ7W002Q2MBW8-4ONedruIWMpw8BXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
                .build();
        */

        // See documentation on defining a message payload.
        Message message = Message.builder()
                .putData("score", "850")
                .putData("time", "2:45")
                .setToken("fh4Jcwe3vhg:APA91bGvw6crsojSroBE31aeR32ZRjfJyCisHNUWiR6froP53c0YpQ7uG-EtkiPIQ0ZUnY2fYW_TF4T6NFhQ7W002Q2MBW8-4ONedruIWMpw8BXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
                .build();


        // Send a message to the device corresponding to the provided
        // registration token.
        String response = null;
        try {
            System.out.println("TEST : " + FirebaseMessaging.getInstance());
            response = FirebaseMessaging.getInstance().sendAsync(message).get();
            // Response is a message ID string.
            System.out.println("Successfully sent message: " + response);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ExecutionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

请帮忙

小智 6

官方Firebase 文档说:

在许多情况下,现有的注册令牌可能不再有效,包括:

  • 如果客户端应用程序取消注册 FCM。
  • 如果客户端应用程序自动取消注册,这可能会在用户卸载应用程序时发生。例如,在 iOS 上,如果 APNS 反馈服务报告 APNS 令牌无效。
  • 如果注册令牌过期(例如,Google 可能决定刷新注册令牌,或者 iOS 设备的 APNS 令牌已过期)。
  • 如果客户端应用程序已更新但新版本未配置为接收消息。

对于所有这些情况,请从应用服务器中删除此注册令牌并停止使用它来发送消息。

通常,当后端应用程序发送带有过期令牌的推送时,您会收到此错误。


moi*_*tab 2

该错误NotRegistered意味着您的网络应用程序未注册,或者您在“to”字段中使用的密钥不正确。在你的情况下,我怀疑密钥是用两行写的,并且可能在请求中发送了退格键。尝试在一行中发送“收件人”字段键。