NaySoftware / go-fcm

Firebase Cloud Messaging ( FCM ) Library using golang ( Go )
GNU General Public License v2.0
230 stars 93 forks source link

Topic Notification returns 200 OK, but no Successes #22

Open p3lli opened 6 years ago

p3lli commented 6 years ago

Hello and thank you for developing this package.

I was trying to use Topic Subscription and Topic Notification, but I'm having some difficulties.

When I try to subscribe a token to a topic, fmt.Printf("Firebase response is: %v", response) returns Firebase response is: &{ [map[]] 200 OK 200}.

When then I try to send a message to that topic, response is {true 200 0 0 0 0 [] NUMERIC_CODE }.

It seems like I have messed up something in the subscription, but I don't know what.

// subscription snippet
package subscription

apiKey := "API_KEY"
topics := []string{"/topics/t1", "/topics/t2"}
tokens := []string{"token1", "token2", "token3"}
client := fcm.NewFcmClient(apiKey)
for _, topic := range topics {
  response, err := client.BatchSubscribeToTopic(tokens, topic)
  if err != nil {
  // log err
  }
}

// sending snippet
package sending

apiKey := "API_KEY"
payload := &fcm.NotificationPayload{
  Title:  "title"
  Body: "body"
}
client = fcm.NewFcmClient(apiKey)
client.SetNotificationPayload(payload)
data := map[string]string{
  "source":   "source",
  "category": "category",
}
topics := []string{"/topics/t1", "/topics/t2"}
for _, topic := range topics {
  client.NewFcmMsgTo(topic, data)
}
status, err := client.Send()
if err != nil {
  // log err
}

If I try to send the same message using NewFcmRegIdsMsg it works

// sending snippet
package sending

apiKey := "API_KEY"
payload := &fcm.NotificationPayload{
  Title:  "title"
  Body: "body"
}
client = fcm.NewFcmClient(apiKey)
client.SetNotificationPayload(payload)
data := map[string]string{
  "source":   "source",
  "category": "category",
}
tokens := []string{"token1", "token2", "token3"}
client.NewFcmRegIdsMsg(tokens, data)
status, err := client.Send()
if err != nil {
  // log err
}

Thank you for your attention

firyalff commented 2 years ago

Hello, is there any information related to this issue? currently i'm facing the same problem