Android GCM SENDER_ID, how to get it?

2020-01-27 19:28发布

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.

10条回答
别忘想泡老子
2楼-- · 2020-01-27 20:20

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.

查看更多
相关推荐>>
3楼-- · 2020-01-27 20:21

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

查看更多
兄弟一词,经得起流年.
4楼-- · 2020-01-27 20:21

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

查看更多
放荡不羁爱自由
5楼-- · 2020-01-27 20:27

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.

查看更多
登录 后发表回答