firebase / firebase-admin-dotnet

Firebase Admin .NET SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
366 stars 131 forks source link

SenderId mismatch #296

Closed anoam closed 3 years ago

anoam commented 3 years ago

Hey there! I'm trying to start using Firebase for push notifications. I've downloaded the key file and trying to run this code.

var sender = FirebaseApp.Create(
  new AppOptions
    {                
       Credential = GoogleCredential.FromFile("/path/to/my/key.json")
     }
);

var message = new Message
  {
    Data = new Dictionary<string, string>
      {
        { "foo", "bar" }
      },
     Token = "" // the token is here
  };

await FirebaseMessaging.DefaultInstance.SendAsync(message);

But I get the following exception:

System.AggregateException: One or more errors occurred. (SenderId mismatch)
 ---> FirebaseAdmin.Messaging.FirebaseMessagingException: SenderId mismatch
   at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndReadAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndDeserializeAsync[TResult](HttpRequestMessage request, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessagingClient.SendAsync(Message message, Boolean dryRun, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(Message message, Boolean dryRun, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(Message message, Boolean dryRun)
   at FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(Message message)

Would you kindly help me to get rid of this?

google-oss-bot commented 3 years ago

I found a few problems with this issue:

hiranya911 commented 3 years ago

It generally means the token and the credential come from 2 different projects. See https://firebase.google.com/docs/reference/admin/dotnet/namespace/firebase-admin/messaging#messagingerrorcode

Please use StackOverflow for usage questions and debugging help.