将设备令牌注册 ID 从 Urban Airship 迁移到 Firebase Cloud Messaging

Migrating device token registration IDs from Urban Airship to Firebase Cloud Messaging

从 Urban Airship Offboarding 文档中,我收到以下信息:

We are sorry to see you leave, but want to make your transition a smooth one. Here are some things you'll want to take care of: Make an API call to access all of your device tokens and GCM registration ID's. Why? This will provice the ability to transition those tokens and ID's so the devices that have already opted in to Push Notifications on iOS won't be prompted to do so again if the Customer owns App Bundle ID. http://docs.urbanairship.com/api/ua.html#device-listing.

我能够通过使用 GET /api/apids 和 http://docs.urbanairship.com/api/ua.html#device-listing "APID Listing" 标题下的信息成功获取注册到我的应用程序的 Android APID。但是,我不确定如何在 Firebase 云消息传递中使用 APID。我想要的是从 Urban Airship 获取我所有的设备令牌和 Firebase Cloud Messaging 注册 ID,但不是 Urban Airship 独有的值。我的印象是,APID 是 Urban Airship 所独有的,就像 Channel ID(在 Java 和 UAirship.shared().getPushManager().getChannelId() 中获得)也是 Urban Airship 所独有的一样。我正在尝试从 Urban Airship 导出设备令牌,以便我可以独立于 Urban Airship 从 Firebase Cloud Messaing 使用它们。换句话说,我想从 Urban Airship 迁移设备。有没有办法以与 FirebaseInstanceId.getInstance().getToken() 方法 returns 相同的格式获取设备令牌?该格式如下所示:

f32EVa9yfbo:AJA91bFg53ZuQLWYSDDqPlkf4a88Lu6Gp4DoXVDJ2wRIlnjDngq0UdNnlSi7wxbbut6YX7Z1kmvyS3bhk_Zrl-1doHCf5XFdOXTThNzo4sXASWqQjHKfNa3pH2Js4Zlbf_CtRkD2Peho

谢谢。

更新 1:

我找到了获取 GCM 注册 ID 的方法:

第 1 步。使用 GET /api/apids 获取注册到此应用程序的 Android 个 APID,以及关联的元数据:

C:\curl>curl -k https://go.urbanairship.com/api/apids/ -u "<AppKey>:<MasterSecret>" -H "Content-Type: application/json" -X GET |more
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0{
  "next_page" : "https://go.urbanairship.com/api/apids/?start=0584f193-07a0-49f7-b2d3-92f8e05ur6b5&limit=1000",
  "apids" : [ {
"tags" : [ "City-1" ],
"alias" : null,
"active" : false,
"created" : "2017-07-17 23:02:40",
"apid" : "00027235-66b4-4433-a40f-254532d8abd1"
  }, {
"tags" : [ "City-1" ],
"alias" : null,
"active" : true,
"created" : "2017-09-14 15:41:35",
"apid" : "00036ca3-d628-4353-be92-0dc6fe03afc6"
      }, {
"tags" : [ "city-2" ],
"alias" : null,
"active" : true,
"created" : "2017-09-18 16:38:39",
"apid" : "000222f5-824a-42f2-8ba0-c58b4c2fb2a2"
  }, {
"tags" : [ "city-2" ],
-- More  --

结果是一个包含许多 api 的长数组

步骤 2. 使用 GET /api/apids/(APID) 获取特定 Android APID 的信息

C:\curl>curl -k https://go.urbanairship.com/api/apids/000222f5-824a-42f2-8ba0-c58b4c2fb2a2 -u "<AppKey>:<MasterSecret>" -H "Content-Type: application/json" -X GET
{"last_registration":"2017-12-14 17:36:05","created":"2017-10-19 17:05:18","gcm_registration_id":"bIY0GH6-hqk:APA91bH2xUBtlfga2kBG0GjvjbBYrI3M72BbXc3tTo7pSuY61w1wrgOeTbEqEd5J2SmUcQx25uU8TafWk2tDP7Vf7bc0ZsQrtENlFJDNIb--LUVuZimjOegyaepPYuQvm_9gmJDsviwY","apid":"000222f5-824a-42f2-8ba0-c58b4c2fb2a2","alias":"","active":true,"tags":["city-2"]}

现在我看到以 Firebase Cloud Messaging 可以识别为设备令牌 ID 的格式返回的内容,并且我可以使用它从 Firebase Cloud Messaging 发送推送通知而无需 Urban Airship:

bIY0GH6-hqk:APA91bH2xUBtlfga2kBG0GjvjbBYrI3M72BbXc3tTo7pSuY61w1wrgOeTbEqEd5J2SmUcQx25uU8TafWk2tDP7Vf7bc0ZsQrtENlFJDNIb--LUVuZimjOegyaepPYuQvm_9gmJDsviwY

现在,我看到的复杂情况是,正如您在上面看到的那样,我必须提供特定的 APID 才能接收该 APID 的 gcm_registration_id。当我只使用 GET /api/apids 作为我在上面的步骤 1 中的示例时,我在返回的数组中没有得到任何 gcm_registration_id。这使得获取 gcm_registration_id 值的过程极其繁琐和漫长,因为我必须像我在步骤 2 中编写的示例中那样使用 GET /api/apids/(APID),对于每个返回的 APID "GET /api/apids" 我在步骤 1 中写的。例如,如果我有 70,000 个 APID 值,我将不得不执行这个繁琐的过程 70,000 次,除非我编写脚本或某种方式来自动执行下载 APID 的过程。当我在第 1 步中使用 GET /api/apids 时,我是否可以立即接收元数据中数组的一部分 gcm_registration_id 值?这将有助于下载 gcm_registration_id 值的过程,以便我可以在 Firebase 云消息传递中使用它们。

此外,如果我看到的 gcm_registration_id 值是我可以在 Firebase 云消息传递中用于向设备发送推送通知而无需使用 Urban Airship 的设备令牌 ID 值,我希望收到确认。

更新 2:

问题是我需要使用 https://go.urbanairship.com/api/apids/{apid} 才能看到 gcm_registration_id 值,我不想这样做,因为如果我有 70,000 个注册设备,我将不得不进行 70,000 个 cURL 查询,提供 70,000 个 {apid} 值中的每个值 70,000 次。这将需要永远!如果我只使用 https://go.urbanairship.com/api/apids/ 而没有 {apid},则返回的数组不包含 gcm_registration_id 个值。

更新 3:

编写 Java 代码并请求 https://go.urbanairship.com/api/apids to obtain and store an array of APID values, and then pass each element of that array as the the {apid} to then make a loop of requests to https://go.urbanairship.com/api/apids/{apid} in order to obtain all of the GCM/FCM device tokens registered to my app? I guess a single cURL request to https://go.urbanairship.com/api/apids 的解决方案可能不足以获取注册到我的应用程序的所有 GCM/FCM 设备令牌; Java 代码中的请求、数组和循环可能是获取我尝试下载的那些令牌所必需的。如果有人能证实这一点,我将不胜感激。

我收到了 Urban Airship 支持中心的回复,他们向我解释说 Android 设备的 GCM/FCM 令牌,他们称之为 push_address。我去验证了这些值,发现它们具有 Firebase Cloud Messaging 使用的格式,因此我终于可以使用 Urban Airship API 下载令牌。这是他们技术支持的回复:

[Name of Employee] (Urban Airship Support Center)

Dec 20, 5:10 PM PST

Hi Jaime,

This is [Name of Employee] with Urban Airship Technical Support.

Try using the /api/channels endpoint. The push_address value should be the GCM/FCM token for Android devices. The response is paginated and contains a next_page value.

If you need any help pulling the data from this endpoint, or it does not contain the data you are looking for, please let me know.

Thank you, [Name of Employee] Urban Airship Technical Support Portland, Oregon

我正在使用以下请求,您可以看到我如何获得 GCM/FCM 设备令牌。注意:我随机更改了令牌中的字符,但您仍然可以看到格式。

C:\curl>curl -k https://go.urbanairship.com/api/channels/ -u "<AppKey>:<MasterSecret>" -H "Content-Type: application/json" -X GET |more
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
100  683k    0  683k    0     0   227k      0 --:--:--  0:00:03 --:--:--  205k
{"ok":true,"channels":[{"channel_id":"00099045-24a4-2523-a80f-876423d8abd2","device_type":"android","installed":false,"background":false,"push_address":"c2XddiCxuLf:APA91bG8-XqUuyZKnf3A0zJI7xFi3_KsOvyS7X9t2fDYpECKhMGcMdcIjggRfFcr0GAnQCDB9qRn9goC1wcVWxT2aapu578v83LlcgsgqvPFC0dZCVNi0CTZyRA4A4B0dQY7aVgWhxh2","named_user_id":null,"alias":null,"tags":["city-1"],"tag_groups":{"timezone":["America/Costa_Rica"],"ua_android_app_version":["1.21"],"ua_locale_country":["US"],"ua_locale_language":["es"],"ua_android_sdk_version":["8.3.X"],"ua_android_version":["5.1.X"],"ua_location_enabled":["false"],"ua_opt_in":["false"],"ua_background_enabled":["false"]},"created":"2017-07-17T23:02:40","opt_in":false,"last_registration":"2017-08-05T02:33:26"},{"channel_id":"00032ba5-d613-4323-be92-0ac6fe04cfd6","device_type":"android","installed":true,"background":true,"push_address":"ceG5aSa0i6o:ERT91bF0UPUvbEzP4UnlwonfyFVc55FcecQkCesXcqhJglY5UlqIAN88VwH7xadEIoWj4FsHZsYu56jiHzUJqozPawXPGNPW71TbVFeFLVNWBkzpqDgt-8Kftj-ce_Z_vpKNIrXvlAwQ","named_user_id":null,"alias":null,"tags":["city-1"],"tag_groups":{"timezone":["America/Chicago"],"ua_android_app_version":["1.21"],"ua_locale_country":["SV"],"ua_locale_language":["es"],"ua_android_sdk_version":["8.3.X"],"ua_android_version":["6.0.X"],"ua_location_enabled":["false"],"ua_opt_in":["true"],"ua_background_enabled":["true"]},"created":"2017-09-14T15:41:35","opt_in":true,"last_registration":"2017-12-20T13:12:09"},.........

更新 1: 在哪里可以找到我上面显示的代码的 <AppKey>:<MasterSecret>?它位于 https://go.urbanairship.com/apps/。转到设置页面并在下面我用椭圆突出显示的区域中找到它:

更新 2: 如果我们知道 Urban Airship channel_id,我们可以得到 push_address(Urban Airship 所称的 push_addressGCM/FCM device token ID)。例如,假设我知道我的 phone 的城市飞艇 channel_id88cb7c8a-a207-4136-b55f-97d7238df916。然后我可以使用 Airship API (https://docs.airship.com/api/ua/) 执行以下 cURL 命令:

C:\curl>curl -k https://go.urbanairship.com/api/channels/88cb7c8a-a207-4136-b55f-97d7238df916 -u "<AppKey>:<MasterSecret>" -H "Content-Type: application/json" -X GET |more
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
100   739  100   739    0     0    739      0  0:00:01 --:--:--  0:00:01  1213
{"ok":true,"channel":{"channel_id":"88cb7c8a-a207-4136-b55f-97d7238df916","device_type":"android","installed":true,"background":true,"push_address":"cbDusDAn_zE:APA91bF9su16_w4DD5qE5OgM_4E23FvIQJa84UWtvUz7zcdFf3B9WijdL1v1IaWwQTSg74doE_RMdJiCvYH1hJgWS7ELaujxhdz1SQ24EInef9JKfz3a27PTRYreTG_vMuTYkLa5T7f5","named_user_id":null,"alias":null,"tags":["guatemala-city"],"tag_groups":{"timezone":["America/Chicago"],"ua_android_app_version":["1.24"],"ua_locale_country":["US"],"ua_locale_language":["en"],"ua_android_sdk_version":["8.3.X"],"ua_android_version":["6.0.X"],"ua_location_enabled":["false"],"ua_opt_in":["true"],"ua_background_enabled":["true"]},"created":"2018-12-26T14:56:44","opt_in":true,"last_registration":"2019-05-18T06:55:39"}}

C:\curl>