58

I am developing an Android app and I'd like to start testing out push notifications. From a code perspective, I'm all set. My current challenge is that I simply do not know how to get a Google Cloud Messaging API key from Google.

There are loads and loads of tutorials and videos online showing how this can be done in about 10 seconds but Google has recently updated it's developer center and none of the tutorials seem to apply any more. The current process seems very cumbersome and not at all similar to what I've seen online.

I realize that this barely passes as a programming question (if at all) but there is no way that I'm going to even begin to be able to develop anything without an API key from Google.

Is someone able to point me in the right direction?

Dave Ostrander
  • 615
  • 1
  • 5
  • 6

5 Answers5

76

CommonsWare was right about three years ago (2013). This is a revision to his answer.

Note: Even if you have already enabled any services and have API keys this will still work.

  1. Log in to Google Services with your google account. (This is not the same as the Google Console)

  2. Click on Pick a Platform

  3. Click on Enable services for Android

  4. Fill out the app name and package name

  5. Select Cloud Messaging. (Or any other service you want. You can come back to this later and add more)

  6. Click on Generate Configuration Files

  7. Boom. Right there on top in the Cloud Messaging card under Server API key

  8. Also, you will want to download the google-services.json file and copy it to the app/ or mobile/ module directory in your Android project

Chad Bingham
  • 32,650
  • 19
  • 86
  • 115
  • 1
    Hopefully enough upvotes will get this answer to the top. It is possible to generate an API key through the developer console however, and I left a message for CommonsWare letting him (them) know that. – akousmata Jul 13 '15 at 15:36
  • The only option I get in 'App Name' is 'Google Play Android Developer'. I want to reference my apps in the play store but they don't seem to be showing up. Is there some difference between the "Google Play Developer Console" and the "Google Developers Console" that I'm not aware of? If so, how do I link them? If they are already linked, then what name do I use for #4 in reference to the app (App store name is no good because my app has an '&' and that character isn't allowed in #4. – kraftydevil Oct 06 '15 at 09:06
  • Or maybe it's the package name that really matters and the app name is a just an identifier? – kraftydevil Oct 06 '15 at 09:16
  • 1
    @kraftydevil Yes your app name is just an identifier for you. Your package name wont be there until you manually type it in. – Chad Bingham Oct 11 '15 at 21:03
  • @RyanH. you mean 2016? – Chad Bingham Oct 13 '16 at 21:27
  • 2016-10-13: Currently, this seems to be the ONLY way to do it. (Thanks for date correction @ChadBingham. I could not edit, so I deleted.) – Ryan H. Oct 14 '16 at 16:47
49

but Google has recently updated it's developer center and none of the tutorials seem to apply any more

:: sigh ::

That's yet more work for my next book update...

The current process seems very cumbersome and not at all similar to what I've seen online.

Bearing in mind that I am already set up with keys, and therefore may be seeing somewhat different stuff than would somebody with no keys:

Step #1: Log into https://cloud.google.com/console with your Google account

Step #2: In the navigation on the left, go into "APIs & auth > APIs"

Step #3: Find "Google Cloud Messaging for Android" and click the "OFF" button next to it (note: this might involve then agreeing to additional terms of service)

Step #4: In the navigation on the left, go into "APIs & auth > Registered apps"

Step #5: Wait a really long time, apparently.

Step #6: Click the red REGISTER APP button.

Step #7: Give the app a name and choose Web Application, then click Register

Step #8: Click the "Server Key" section for your server key

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Ugh...I'm an idiot...ish. When previously trying to register my app, I was choosing "Android" which was requiring me to enter additional info that I did not have and was not going to have for a while. Using "Website" to register the app made everything super easy...assuming that the API key generated works. – Dave Ostrander Nov 08 '13 at 19:27
  • 3
    I would never guess to choose `WebApplication` instead of Android . I was struggling my head trying to use that API Key generated when I chose Android for platform.....even passed my phone number :X – AlexAndro Nov 11 '13 at 20:20
  • go into "APIs & auth > Registered apps" Nope. Not there. – nVentimiglia Apr 13 '15 at 16:50
  • @nVentimiglia: This answer is ~18 months old, and Google redesigns the site from time to time. As I avoid using Play Services in general, I cannot tell you what the current site structure is. – CommonsWare Apr 13 '15 at 16:53
  • 4
    @CommonsWare ::sigh:: is right, it's updated again and this post is old. Starting at step #2, instead of `APIs` go to `Credentials` -> create new key -> click Server Key -> enter IP ranges you want it restricted to (or leave blank) -> click Create, done. – akousmata Jul 13 '15 at 15:35
  • Seems like Google has changed things up yet again. First, there is now only "Google Cloud Messaging" with no variants such as Android or Chrome. And even when enabled, I still can't create a server key. There is a Service key but that's different and for API key I get no server option; it just creates a key right away which doesn't work (returns 401 unauthorized). – Ryan H. Oct 13 '16 at 20:38
  • A few steps may changed but the step #5 is actually the most important (I only can make it work with Amazon's notification-service, just the next day that I've created the key). – ecolell Dec 08 '16 at 21:56
  • https://support.clevertap.com/docs/android/how-to-find-your-gcm-sender-id-and-gcm-api-server-key.html – Peter Aug 10 '17 at 08:16
5

Google has updated their api console recently to Google Cloud Console. In short terms , you need to create an Android application and pick Accessing APIs via a web server. this service has a detailed guide for that

Orr
  • 4,740
  • 3
  • 28
  • 31
  • 5
    seems some of us aren't getting shown a "Registered Apps" submenu option. – jrg Dec 19 '13 at 13:42
  • It might be a permission issue - do you have admin permissions on that Google account? – Orr Dec 20 '13 at 14:51
  • 1
    Turns out they've renamed/moved options about (at least, in the views *I* get) but not updated their documentation to reflect that. Go to APIs & Auth > Credentials. If you're simply wanting your web app to send GCMs then use the API key value from 'Key for server applications' - you'll need to add your IP addresses into the list. – jrg Jan 02 '14 at 12:42
  • They updated their documentation now... from my understanding, you need a Browser Key and don't put anything in the ip list – Orr Jan 13 '14 at 11:00
4

The easiest way to configure GCM API key and Sender ID, is to Google login with your account and continue the Wizard : https://developers.google.com/mobile/add :)

Harry Suren
  • 676
  • 1
  • 12
  • 23
Manikandan K
  • 911
  • 9
  • 21
1

To get FCM (Firebase cloud messaging) key for a web app

  1. login into Firebase
  2. Create a new app by clicking the big 'Add Project' button

    Wait a few seconds and watch the circle chase its tail

  3. Click "Add Firebase to your web app "

  4. Copy the api key
charsi
  • 2,917
  • 22
  • 40