Android GCM SENDER_ID,如何获取?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11294602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:48:19  来源:igfitidea点击:

Android GCM SENDER_ID, how to get it?

androidgoogle-cloud-messaginggoogle-api-consolesender-id

提问by Zelter Ady

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

我尝试迁移到GCM,我有一个问题,与SENDER_ID我需要提供。我使用谷歌的演示项目。在这个项目中,如果我理解这一点,我需要SENDER_ID在 CommonUtilities.java 文件中为应用程序提供一个。

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).

我提供的 SENDER_ID 是我在https://code.google.com/apis/console/ 上注册的 API 密钥,格式如下AIzaSyAxxxxxxx_xxxxxxxxxxxnoGZw:(共 40 个字符)。

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

SENDER_ID我在“BroadcastReceiver mHandleMessageReceiver”上使用此字符串时,会显示一条错误消息:来自 GCM:错误 (INVALID_SENDER)。.

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

错误在哪里?我提供的字符串不是SENDER_ID?

Thank you.

谢谢你。

回答by azgolfer

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:

不,SENDER_ID 是您在 Google API 控制台注册的项目 ID,它应该是一个数字字符串。例如,在您的浏览器 URI 上,您应该会看到:

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

The Sender ID is 4815162342

发件人 ID 为 4815162342

Updated Answer:

更新答案:

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

Google 尚未完全更新其文档。上面的答案是旧的,它基于此文档,似乎仍未更新。

According to updated Google docs, it seems that Project Numberon Google API Consoleis used as SENDER ID

根据更新的谷歌文档,似乎谷歌 API 控制台上的项目编号被用作发送者ID

回答by Hiren Patel

I have done for Latest Google API Console.

我已经完成了最新的 Google API 控制台

How to get SenderId:

如何获得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 SenderIdform there
  1. 打开 Google api 控制台
  2. 创建项目
  3. 单击左侧菜单图标
  4. 点击谷歌云平台
  5. 你会在SenderId那里得到表格

Reference:

参考:

enter image description here

在此处输入图片说明

Hope this will help you.

希望这会帮助你。

回答by PankajAndroid

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_IDyou have to use

转到您的Google API 控制台页面。从左侧的下拉菜单中选择您使用的项目。选择概览,现在您可以看到您了project number。这是SENDER_ID你必须使用的

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

获取项目编号的另一种方法是从您的 url 中获取“project”的值。您的网址必须是这样的:“ https://code.google.com/apis/console/b/0/#project:886025556782”。这里的项目编号是“886025556782”。这个号码是 SENDER_ID

回答by Adam

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

如果您最近创建了 API 项目,则为2014 年 11 月的更新答案。

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.

首先,正确,您绝对应该转到 Google Developers Console 并找到启用了 GCM 的项目。查看概览部分(左侧导航面板)时,您会看到右侧列出了项目 ID 和项目编号。项目 ID 对我来说失败了(这就是我在这里的原因),但是当我尝试使用项目编号时,我现在可以正确注册我的客户了。

Notethat 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.

请注意,这是不同的,因为 Google 最近修改了他们分配项目 ID 的方式。十月份我做了一个项目,并得到了一个全数字的项目 ID,我认为它可以正常工作。但是我今天创建的那个有一个两个词和一个数字 ID(如 Hamster-Party-420)和一个数字项目编号。我的项目的 URL 包含 Hamster-Party-420,项目编号仅在概览屏幕上可见。

回答by Dexter

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

另一个更新的答案,对困惑的解释很少(..就像我一样)。(感谢@azgolfer、@PankajAndroid 和@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 numericbut alpha numeric like master-xxxxx-1234. Project numberis a 11 digit number like 123456789100.

1- 如果您在https://console.developers.google.com 上创建项目,您可以在项目概览中看到“项目 ID”和“项目编号”两件事。项目 ID 不再是数字而是字母数字,如master-xxxxx-1234项目编号是 11 位数字,如 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

2 -即使你检查浏览器链接,你可以找到它: https://开头console.developers.google.com/项目/主-XXXXX-1234

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

那么 master-xxxxx-1234 是 SENDER_ID(在某些地方称为 PROJECT ID)吗?不。

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

您必须使用项目编号作为 GCM 中的项目 ID。

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

3- 在哪里可以交叉检查项目 ID 是否被用作项目 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.

在 API 仪表盘上。(网址:https: //code.google.com/apis/console/b/0/?noredirect#project : 12345678900 - 其中 12345678900 是您在项目仪表板上的项目编号。

google api dashboard

谷歌 API 仪表板

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.

总结:项目仪表板和 API 仪表板中的项目 ID 不同。project dashbaord 中的项目编号用作 API Dashboard 中的项目 id,项目 dashbaord 中的 Project Id 用作 API Dashboard 中的项目名称。因此,我们在开发者控制台中创建项目时,项目仪表板中显示的项目编号将用作 GCM 中的 SENDER_ID。

回答by Micro

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

前往最新版开发者控制台的“仪表盘”,点击“项目:海龟之力”下方的下拉箭头,即可看到项目编号!将其用作您的 SENDER_ID

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

(假项目所以不要尝试=P)

enter image description here

在此处输入图片说明

回答by insomniac

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

也许您还没有在 API 控制台中为 Android 激活 Google Cloud Messaging。以下是说明:

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

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

回答by Tyler Brock

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

我们花了几个小时试图弄清楚这一点。问题是我们的 android manifest 没有包含发件人 id!

回答by Josh Wolff

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

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

enter image description here

在此处输入图片说明

回答by sud

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

您使用的 SENDER_ID 只是授权密钥。您可以在您的项目 Google API 控制台页面 URL 中找到 SENDER_ID

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

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

here 8543162367will 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

这里8543162367将是您的 SENDER_ID ,并且项目 ID 不再是数字,它的字母数字或仅数字或仅字母任何东西,但其位置与我显示的相同