订阅主题突然引发& quot; java.io.IOException:InternalServerError& quot; [英] Subscribe to topics suddenly throws "java.io.IOException: InternalServerError"

查看:86
本文介绍了订阅主题突然引发& quot; java.io.IOException:InternalServerError& quot;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从今天开始,我遇到了GCM订阅主题"以下问题.Nexus 6,Android 6.0.1,Google Play服务9.0.83在应用中使用google-play-services:8.3.0.

since today I encountered the following issue with GCM "subscribe to topics". Nexus 6, Android 6.0.1, Google Play Services 9.0.83 Using google-play-services:8.3.0 in app.

第1步

我遵循Google的文档,通过实例ID获取令牌.获取令牌后,我成功订阅了"topics/global"主题,并将令牌存储在共享首选项中.

I follow the documentation from Google for getting the token through the instance id. After getting the token I successfully subscribe to the "topics/global" topic and store the token in the shared preferences.

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".当然可以捕捉到例外,但是我不知道现在该如何进行.

After some time / on user interaction I want to subscribe to additional topics. I fetch the token from the shared preferences and try to subscribe like before, but this time it fails with the "java.io.IOException: InternalServerError". The exception is catched of course, but I do not know how to proceed now.

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 Cloud Messaging(FCM)带来了重大变化吗?

This process worked for the last 5 months without issues. Suddenly, since this morning, the subscription to additional topics (step 2) fails. Any idea if the switch to Firebase Cloud Messaging (FCM) brought breaking changes?

当前我所有的客户端应用程序都不可用.快速的帮助真是感激不已.

Currently all my client apps are not usable. Fast help is really appreciated.

推荐答案

我是Google Cloud Messaging团队的成员.

I am part of the Google Cloud Messaging team.

我们在支持的文档中发现了一个问题,该问题在过去24小时内影响了一小部分主题订阅.该问题已得到解决,订阅应该可以在所有设备上正常工作.

We identified an issue in our backed that affected a small percentage of the topic subscriptions during the last 24 hours. The issue has already been fixed, and the subscriptions should work correctly on all devices.

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

Please let us know if you are still experiencing this error.

感谢Steffen报告此问题.

Thanks Steffen for reporting the issue.

这篇关于订阅主题突然引发&amp; quot; java.io.IOException:InternalServerError&amp; quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆