Firebase 云消息传递返回无效注册

时间:2021-06-22 06:13:15

标签: android kotlin firebase-cloud-messaging retrofit

我将 FCM 与主题订阅一起使用。我也在使用 HttpLoggingInterceptor

这是我的代码:

btn_send.setOnClickListener {
            val title = et_title.text.toString()
            val message = et_message.text.toString()
            if (title.isNotEmpty() && message.isNotEmpty()) {
                val sendNotification = SendNotification(
                    NotificationData(title, message),
                    TOPIC
                )
                sendNotification(sendNotification)
            }
        }

sendNotification():

private fun sendNotification(sendNotification: SendNotification) = CoroutineScope(Dispatchers.IO).launch {
        Log.i("sendNotification", "came here")
        try {
            val interceptor = HttpLoggingInterceptor()
            interceptor.setLevel(HttpLoggingInterceptor.Level.BODY)

            val okHttpClient = OkHttpClient.Builder().addInterceptor(interceptor).build()

            val retrofit: Retrofit = Retrofit.Builder()
                .baseUrl("https://fcm.googleapis.com")
                .addConverterFactory(GsonConverterFactory.create())
                .client(okHttpClient)
                .build()
            val response = retrofit.create(PushNotification::class.java).send(sendNotification)
            if (response.isSuccessful){
                Log.i("response", "successful")
            }
        }catch (e: Exception){
            Log.i("btn_send", e.toString())
        }
    }

我在日志中收到此响应:

{"multicast_id":5581707023196108823,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

我在日志中收到 200 响应以及此错误。这是为什么?

我在清单中添加了 Internet 权限,并且在我的项目中添加了服务器密钥。我还需要添加什么吗?

0 个答案:

没有答案