Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The registration token is not a valid FCM registration token #363

Open
jitendrajadav opened this issue Sep 21, 2023 · 1 comment
Open

The registration token is not a valid FCM registration token #363

jitendrajadav opened this issue Sep 21, 2023 · 1 comment

Comments

@jitendrajadav
Copy link

I trying to send push notification through web APi .net core 7 where I have installed FirebaseAdmin Nuget packages version 2.4.0 and my configuration is

// Get the current directory and append the relative path to the JSON file var serviceAccountKeyPath = System.IO.Path.Combine(Environment.CurrentDirectory, "serviceAccountKey.json"); // Initialize the default app var defaultApp = FirebaseApp.Create(new AppOptions() { Credential = GoogleCredential.FromFile(serviceAccountKeyPath), });

and I am sending message like below snippet

`var messages = new List();
foreach (var item in tokens.Split(','))
{
string trimmedToken = item.Trim();

// Create a message
var message = new Message
{
    Notification = new Notification
    {
        Title = model.Title,
        Body = model.Message,
    },
    Token = trimmedToken, // The device token of the recipient
};
messages.Add(message);

}

BatchResponse response = default;
try
{
response = await FirebaseMessaging.DefaultInstance.SendAllAsync(messages);

// Check for a successful response
if (response != null)
{
    Console.WriteLine("Successfully sent message: " + response);
}
else
{
    Console.WriteLine("FCM response is null.");
}

}
catch (FirebaseException ex)
{
Console.WriteLine("Error sending FCM message: " + ex.Message);
Console.WriteLine("Error code: " + ex.ErrorCode);
// Handle the error appropriately
}`

I am getting error saying

The registration token is not a valid FCM registration token

image

But same token I am sending using firebase console it is working fine

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Android 11
  • Firebase AdminSDK version: 2.4.0
  • Firebase Product: Push Notification
  • .NET version: .net core 7
  • OS: windows 11

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

  1. Create Xamarin forms application.
  2. Setup firebase Push notification plugin and android manifest.
  3. Get Token from refresh token if in debug or else token
  4. try to send Push Notification using Token.
  5. here you will get error

Relevant Code:

https://github.com/jitendrajadav/PushNotificationPoC

@google-oss-bot
Copy link

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants