【发布时间】:2021-04-02 07:59:31
【问题描述】:
几天以来,我的应用无法再从我的 android 应用创建设备组。根据 Firebase 文档,我们应该能够从服务器或客户端管理设备组。几年来我没有改变我的应用程序!所以我想在文档中没有任何参考的情况下发生了一些变化。目前我的应用可以:
JSONObject data = new JSONObject();
data.put("operation", "add");
data.put("notification_key_name", notificationKeyName);
data.put("registration_ids", new
JSONArray(Collections.singletonList(registrationId)));
data.put("id_token", idToken);
RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, data.toString());
Request oreq = new
Request.Builder().url("https://fcm.googleapis.com/fcm/googlenotification")
.addHeader("project_id", projectId)
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json")
.post(body)
.build();
其中通知密钥名称是用于检索令牌的 Google 帐户的用户电子邮件
String idToken = GoogleAuthUtil.getToken(this, account, scope);
并使用检索注册ID
FirebaseMessaging.getInstance().getToken()
当应用程序现在发送请求时,结果是“发件人被拒绝”,但正如我所说,我没有更改任何内容。但是,在 Firebase 文档中,我找不到任何对端点 https://fcm.googleapis.com/fcm/googlenotification 的引用,所以它有什么改变吗?
我使用 firebase doc 跟踪网页,发现与设备组的客户端 android 应用管理相关的部分已在一年前,即 2020 年 3 月 18 日被删除。
【问题讨论】:
-
基于此链接firebase.google.com/docs/cloud-messaging/android/…,我发现他们将端点更改为fcm.googleapis.com/fcm/notification,并且他们还在标题中添加了:Authorization:key=API_KEY。
-
实际上从那个链接他们仍然说您可以从 Android 客户端应用程序管理组,但他们不再说如何。您所谈论的部分实际上是服务器部分,在示例中使用了服务器密钥。他们于 2020 年 3 月 18 日更改了网页,但不清楚原因。
-
是的,你是对的,他们删除了该部分。
-
我已经根据服务器部分指南(管理应用服务器上的设备组)@987654324,使用新 url:fcm.googleapis.com/fcm/notification 在标头中使用 Authorization:key=API_KEY(服务器密钥)测试了此请求@ 并且它有效,响应是 notification_key。我没有找到与客户端应用相关的任何其他内容。
-
是的,我知道,我也尝试过,但这不是我想要的。我不能简单地在 android 应用程序中添加服务器密钥。
标签: android firebase firebase-cloud-messaging