Firebase 通知和用户 ID

Nic*_*nge 7 notifications android node.js firebase

我正在将 Firebase 与 Android 应用程序(身份验证、数据库和通知)一起使用。

我正在尝试从外部服务器(在 nodejs 中)发送通知,以便用户可以向另一个用户发送通知。

因此,Android 应用程序会记住一个 UserId 列表(与 Firebase Auth 中的 ID 相同),然后将此列表发送到 nodejs 服务器。

有了这个列表,服务器联系 url ' https://fcm.googleapis.com/fcm/send ',但 Firebase 返回一个 InvalidRegistration 因为我发送的是 userId 列表而不是 firebase 创建的注册令牌列表通知。

我应该记住这些令牌还是有办法发送带有用户 ID 的通知?

(当我尝试使用令牌列表时,它当然有效。)

var requestData = {
    "registration_ids": userIds, //Problem is here
    "data": {
      "message": "A message"
     }
  };

  request({
      url: "https://fcm.googleapis.com/fcm/send",
      method: "POST",
      json: true,
      headers: {
          "Authorization": "key=firebaseKey",
          "content-type": "application/json",
      },
      json: requestData
  },
  function(err, response, body) {

  });
Run Code Online (Sandbox Code Playgroud)

Maj*_*man 3

是的你可以。为此,您必须注册这些用户 ID,而不是设备 ID 令牌。然后 firebase 识别了您的用户 ID。

   @Override
    public void onNewToken(@NonNull String token) {

        super.onNewToken(token);
        Log.d("user_token: ",token);
     

    }
Run Code Online (Sandbox Code Playgroud)