Android GCM SENDER_ID, how to get it?
Asked Answered
C

10

84

I try to migrate to GCM and I have an issue with the SENDER_ID I need to provide. I use the demo project from google. In this project I need, if I understand this well, to provide a SENDER_ID to the application in the CommonUtilities.java file.

The SENDER_ID I provided is the API key I registered on https://code.google.com/apis/console/ and has this form: AIzaSyAxxxxxxx_xxxxxxxxxxxnoGZw (total 40 chars).

Using this string as SENDER_ID I get on "BroadcastReceiver mHandleMessageReceiver" an error message: From GCM: error (INVALID_SENDER)..

Where is the mistake? The string I provide is not the SENDER_ID?

Thank you.

Cumberland answered 2/7, 2012 at 13:23 Comment(2)
Here is a step-by-step process for getting the GCM Sender Id and API Key. - ajaxtown.com/article/…Heliport
After the changes, the information is available elsewhere #38863578Counselor
G
183

No, the SENDER_ID is the project ID you signed up at Google API console, it should a numeric string. e.g. on your browser URI, you should see this:

https://code.google.com/apis/console/#project:4815162342

The Sender ID is 4815162342

Updated Answer:

Google has not updated its docs completely. The above answer is old and its based on this documentation and it seems that its still not updated.

According to updated Google docs, it seems that Project Number on Google API Console is used as SENDER ID

Garretgarreth answered 2/7, 2012 at 14:56 Comment(10)
I did some experiments - I couldn't find an complete answer on the Internet and in the end I discovered that the sender_id is the email used to register to the service. If you want your answer to get mark as accepted, please edit it.Cumberland
Zelter, using email address as the sender_id is the deprecated C2DM way of registration. See here: developer.android.com/guide/google/gcm/c2dm.html, under 'Client Changes': Migration is simple! The only change required in the application is replacing the email account passed in the sender parameter of the registration intent with the project ID generated when signing up for the new service.Garretgarreth
You are right. It works. Thanks for your help! Do you know if the server side may be the same? Should I change something in the server side from the old C2DM version?Cumberland
For server side, it's more involved, the URL link I referenced in the above comment is a good starting place. Basically change the Authorization header to use the new API key, and the Http POST body now accepts a JSON string.Garretgarreth
Thanks azgolfer. How can the migration possibly expect anyone to know this? It's almost as if Google is going out of their way to make it as tricky as possible.Bili
hey @Garretgarreth can you update your answer based on my answer below? https://mcmap.net/q/239948/-android-gcm-sender_id-how-to-get-it GCM has changed from Project ID being used, and they use a Project NumberHemialgia
@Hemialgia and others if we are supposed to use Project Number, why doesn't Google update docs to say that...Multinational
a lot of their docs are unfortunately rather outdated. I suppose we could point out where they're outdated and they may get updated, but I can't imagine how many doc pages for so many different things they have up now. Yikes.Hemialgia
They have updated The docs. Here is the link to updated docs.developers.google.com/android/reference/com/google/android/gms/… Please report if any pages are still outdated :)Morez
SENDER_ID can be found in google-services.json file (configuration file) as "project_number": "12456789".Barling
B
57

I have done for Latest Google API Console.

How to get SenderId:

Steps:

  1. Open Google api console
  2. Create project
  3. Click on Left hand side menu icon
  4. Click on Google cloud Platform
  5. You would get SenderId form there

Reference:

enter image description here

Hope this will help you.

Brianbriana answered 29/3, 2016 at 9:20 Comment(1)
As a note, you should never censor by overdrawing something, instead delete that part by selecting it with a box tool. Both your URI and Projekt-ID are readable to anyone, especially someone with malicious intend.Relevant
D
24

Go to your Google APIs Console page. Select the project you use from the drop down menu on the left. Select Overview and now you can see you project number. It is the SENDER_ID you have to use

Another way to get your project number is to get the value of "project" from your url. Your url has to be like this: "https://code.google.com/apis/console/b/0/#project:886025556782". Here the project number is "886025556782". this number is SENDER_ID

Deckard answered 2/11, 2012 at 11:35 Comment(2)
What if my url from project not shows any no.? actually my url is like this "console.developers.google.com/project/Project ID"Dimpledimwit
Priyank, see my answer. Google changed this a bit recently. https://mcmap.net/q/239948/-android-gcm-sender_id-how-to-get-itHemialgia
H
9

An updated answer as of Nov 2014 IF YOU'VE CREATED AN API PROJECT RECENTLY.

First of all, correct, you should absolutely go to the Google Developers Console and find the Project that you have GCM enabled on. When looking at the Overview section (left-hand nav panel), you'll see Project ID and Project Number listed on the right hand side. Project ID was failing for me (which is what led me here), but when I tried the Project Number, I'm able to register my clients correctly now.

Note that this is different because Google modified how they assign project IDs recently. In October I made a project and was given an all numerical Project ID, which I assume would work fine. But the one I created today was given a two-word and a number id (like Hamster-Party-420) and a numeric Project Number. The URL to my project contains Hamster-Party-420, and the Project Number is only visible on the Overview screen.

Hemialgia answered 19/11, 2014 at 15:1 Comment(0)
S
6

Yet another updated answer with little more explanation for the confused(..like I was).(with due credit to @azgolfer, @PankajAndroid and @Adam)

1- If you create a project at https://console.developers.google.com, you can see two things "PROJECT ID" and "PROJECT NUMBER" in project overview. Project Id is no longer numeric but alpha numeric like master-xxxxx-1234. Project number is a 11 digit number like 123456789100.

project dashbaord

2- Even when you inspect the browser link you can find it as: https://console.developers.google.com/project/master-xxxxx-1234

So is master-xxxxx-1234 is the SENDER_ID (at some places referred as PROJECT ID)? NO.

You have to use the project number as project id in GCM.

3- Where can you cross check that project id is being used as project id?

On API Dashbaord. (url: https://code.google.com/apis/console/b/0/?noredirect#project:12345678900 - where 12345678900 is your project number on project dashboard.

google api dashboard

SUMMARY: Project Id in Project Dashboard and API Dashboard are different. The project number in project dashbaord is used as project id in API Dashboard and Project Id in project dashbaord as Project name in API Dashboard. So the project number shown in the Project Dashboard when we create project in developer console is used as SENDER_ID in GCM.

Sublimation answered 26/12, 2014 at 8:32 Comment(0)
H
4

Go to "Dashboard" in the latest version of the developers console, click the drop down arrow under "Project: Turtle Power" and you can see the Project number right there! Use that as your SENDER_ID

(fake project so don't even try it =P)

enter image description here

Hoopen answered 4/3, 2016 at 21:53 Comment(0)
B
2

Maybe you haven't activated Google Cloud Messaging for Android in API COnsole. Here is the instructions:

http://developer.android.com/google/gcm/gs.html

Bladdernut answered 26/1, 2013 at 15:33 Comment(0)
B
1

We spent hours trying to figure this out. The problem was that our android manifest did not include the sender id!

Bourbonism answered 19/5, 2016 at 23:59 Comment(0)
C
0

If you came here because you are doing web push, Android push, or the like, there is a different answer.

Source: https://firebase.google.com/docs/cloud-messaging/js/client

enter image description here

Conclave answered 31/7, 2019 at 22:9 Comment(0)
K
-3

the SENDER_ID you are using is nothing but the authorization key. you can find the SENDER_ID at your projects Google APIs Console pages URL

https://code.google.com/apis/console/#project:8543162367

here 8543162367 will be your SENDER_ID , and also the Project Id is no longer numeric its alpha-numeric or only numeric or only alphabetic anything but its position is same as shown by me

Krenn answered 16/10, 2015 at 11:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.