2

I already tried so many solutions there to solve it.

Have a lot of unsolved questions here (on stackoverflow) finding for same solution.

When I call:

curl --header "Authorization: key=MY_KEY" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"THE_ID\"]}"

I'm got:

<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

The problem is: every solution here on stackoverflow says "Use the server key, not the browser key". On the current console, when I create a server key, it showme some options and I'm not sure if it right.

Course, I already created some of then. It creates a json file to download, with some data on it... but I really don't know WHERE ARE the SERVER KEY.

What key should I use and where to get it exactly ?


The "create credential" option, where I choose the third one:

The "create credential" option, where I choose the third one

The two options to create a server key:

enter image description here

AL.
  • 36,815
  • 10
  • 142
  • 281
Tiago Gouvêa
  • 15,036
  • 4
  • 75
  • 81
  • Possible duplicate of [Android API key for GCM is suddenly invalid? Unauthorized (401) error](http://stackoverflow.com/questions/37789264/android-api-key-for-gcm-is-suddenly-invalid-unauthorized-401-error) – AL. Sep 24 '16 at 15:58

2 Answers2

2

TL;DR:
To create a sender-id and server-key for GCM or FCM you can use the Firebase Console.
New projects should be created directly in Firebase Console, while existing Cloud Console projects can be imported using Import Google Project from the main page: http://console.firebase.google.com

Once you have a firebase project you can find the GCM / FCM credentials in
Project Setting > Cloud Messaging

More informations:

  1. After importing a Google Project into Firebase the same project will be accessible from both the Cloud Console and the Firebase Console. What changes is that you also have access to the Firebase API.

  2. While we strongly recommended to update the client SDK to Firebase Cloud Messaging, the credentials listed under Project Settings > Cloud Messaging can be used in GCM too.

Diego Giorgini
  • 12,489
  • 1
  • 47
  • 50
0

I get this exception while sending pushnotification to Android devices. This issue got when the serverkey for android device has mismatched. i.e not present with the package. I solved this issue by giving correct serverkey for the package

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 07 '22 at 11:13