订阅主题突然抛出“java.io.IOException:InternalServerError”

时间:2016-05-19 13:07:37

标签: java android google-cloud-messaging firebase-cloud-messaging

从今天起我遇到了GCM“订阅主题”的以下问题。 Nexus 6,Android 6.0.1,Google Play Services 9.0.83 使用google-play-services:应用程序中的8.3.0。

第1步

我按照Google提供的文档获取令牌通过实例ID。 获取令牌后,我成功订阅了“topics / global”主题,并将令牌存储在共享首选项中。

protected void register() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    try {
        // [START register_for_gcm]
        // Initially this call goes out to the network to retrieve the token, subsequent calls
        // are local.
        // R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json.
        // See https://developers.google.com/cloud-messaging/android/start for details on this file.
        // [START get_token]
        InstanceID instanceID = InstanceID.getInstance(this);
        String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
        // [END get_token]
        Log.i(TAG, "GCM Registration Token: " + token);

        // TODO: Implement this method to send any registration to your app's servers.
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        sharedPreferences.edit().putString("token", token).apply();


        // You should store a boolean that indicates whether the generated token has been
        // sent to your server. If the boolean is false, send the token to your server,
        // otherwise your server should have already received the token.
        sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply();
        // [END register_for_gcm]
    } catch (Exception e) {
        Log.d(TAG, "Failed to complete token refresh", e);
        // If an exception happens while fetching the new token or updating our registration data
        // on a third-party server, this ensures that we'll attempt the update at a later time.
        sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply();
    }
    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}

第2步

经过一段时间/用户互动后,我想订阅其他主题。 我从共享首选项中获取令牌并尝试像以前一样订阅,但这次它失败了“java.io.IOException:InternalServerError”。 当然有例外,但我现在不知道该怎么办。

private void subscribeTopics() throws IOException {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    String token = sharedPreferences.getString("token", null);
    if(token == null) {
        Log.e(TAG, "No token");
        return;
    }

    GcmPubSub pubSub = GcmPubSub.getInstance(this);
    for (String topic : TOPICS) {
        pubSub.subscribe(token, "/topics/" + topic, null);  // <--- FAILS HERE
    }
    Log.d(TAG, "Subscribed to topics.");
}

此过程在过去5个月内没有出现问题。突然间,从今天早上开始,订阅其他主题(第2步)失败了。 不知道切换到Firebase云消息传递(FCM)是否会带来重大变化?

目前我的所有客户端应用都无法使用。 非常感谢快速帮助。

1 个答案:

答案 0 :(得分:2)

我是Google云消息传递团队的成员。

我们发现我们支持的问题在过去24小时内影响了一小部分主题订阅。 该问题已得到修复,订阅应在所有设备上正常运行。

如果您仍然遇到此错误,请告诉我们。

感谢Steffen报告此问题。