skip to Main Content

Im trying to send FCM in my kotlin springboot backend.
I can query/write firestore documents successfully.

But when I try to send fcm, I got below error.

message: "handleException /<endpoint> com.google.api.client.http.HttpResponseException: 401 Unauthorized
POST https://fcm.googleapis.com/v1/projects/<project-id>/messages:send"

The Service Account have Firebase Admin, and Firebase Cloud Messaging Admin roles.

Using below code to trigger

package cloudcode.features.firebase

import com.google.firebase.messaging.FirebaseMessaging
import com.google.firebase.messaging.Message
import org.springframework.stereotype.Service

@Service
class FcmService {

  fun sendDataMessage(token: String, data: Map<String, String>) {
    val message = Message.builder()
        .setToken(token)
        .putAllData(data)
        .build()
    FirebaseMessaging.getInstance().send(message)
  }
}

Can’t figure out what im missing.

Any help is appreciated. Thanks in advance.

2

Answers


  1. Chosen as BEST ANSWER

    Found the issue. APNS in FCM wasn't correctly setup that's why there was error.


  2. Did you found the solution i have same problem?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search