android - Google GCM, token 与注册 ID

标签 android google-cloud-messaging

我对注册 ID 和 token 之间的关系感到困惑。在 Google 的 GCM 教程中,我们一开始就注册了一个注册 ID。但是,我们也得到了一个 token 。现在,在图中,我们将注册 ID 发送到目标服务器。但是,我们是否也发送 token ?我知道 token 是从注册 ID 派生的。 token 是否用作 GCM 和应用程序之间的身份验证机制,而服务器永远不知道 token ?

最佳答案

如果您正在寻找有关 Google Cloud Messaging IMO 的基础知识,您可以引用以下内容:

基本上,您需要执行以下步骤:

  1. Google Developers Console 创建一个新项目.在这 步骤,为简单起见,您只需要记下 2 个值:Project Number,其中 将在客户端项目中用作 SENDER_ID;和 API 服务器 key (创建于Credentials), 将在服务器项目中用作API_KEY
  2. 为服务器端创建一个新的简单 Android 项目(使用基本源代码作为我在以下链接中的回答)。
  3. 为客户端创建一个新的简单 Android 项目(在以下链接中使用基本源代码作为我的答案,我从 Google Cloud Messaging - GitHub 的原始源代码定制)。
  4. 运行客户端应用程序,您将获得注册 token (意味着您的设备已成功注册)。然后,将此 token 粘贴(硬编码)到服务器应用程序中的 CLIENT_REGISTRATION_TOKEN 变量(或编写代码以将此 token 发送到服务器应用程序)。

您可以在以下问题中阅读更多内容,其中一个是您之前阅读过的问题之一:

  1. How to implement a GCM Hello World for Android using Android Studio
  2. Adding Google Cloud Messagin (GCM) for Android - Registration process

更多信息:

关键概念来自 Google Cloud Messaging: Overview

Credentials

  • Sender ID A unique numerical value created when you configure your API project (given as "Project Number" in the Google Developers Console). The sender ID is used in the registration process to identify an app server that is permitted to send messages to the client app.
  • API Key An API key saved on the app server that gives the app server authorized access to Google services. In HTTP, the API key is included in the header of POST requests that send messages. In XMPP, the API key is used in the SASL PLAIN authentication request as a password to authenticate the connection. You obtain the API key when you configure your API project.
  • Registration Token An ID issued by the GCM connection servers to the client app that allows it to receive messages. Note that registration tokens must be kept secret.

希望这对您有所帮助!

关于android - Google GCM, token 与注册 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33489862/

相关文章:

android - 同一个第 3 方应用程序服务器是否可以同时满足 CCS 和 GCM 的需求,或者我应该创建两个版本的第 3 方应用程序?

android - 澄清 OneOffTask 上的 setUpdateCurrent

android - 在不发布应用程序的情况下使用 GCM

android - 即使应用程序关闭(滑动/滑动)也会收到 GCM 通知

android - Firebase Analytics 在我的应用中不起作用

android - 如何为 Pantech Element 指定正确的编解码器?

java - Android 运行时 : FATAL exception java. lang.NullPointerException

android - 哪些工具和技术用于将视频从Youtube App转换到Smart TV?

android - 阻止触摸传递到下表面 View

java - 在 fragment 的 onCreateOptionsMenu() 中使用 getActivity() 偶尔会抛出 NPE