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.

Step 1

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);
}

Step 2

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.");
}

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.

  • I have seen the same issue from todays morning. Not sure whats wrong its say the com.google.android.gms signature not valid Found. and have long SHA down – Nikunj Sakhrelia May 19 '16 at 16:07

1 Answers1

2

I am part of the Google Cloud Messaging team.

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.

Thanks Steffen for reporting the issue.

Diego Giorgini
  • 12,489
  • 1
  • 47
  • 50
  • We are not experiencing any issues with GCM/FCM today (CET) and everything seems to run smoothly again. Thank you Diego for the fast answer and the fix. Keep up with the good work. – Steffen Kolb May 20 '16 at 07:17
  • 1
    @Diego Thanks for getting the issue resolved on 5-19. It would appear as though the issue is back again. Invoking the subscribe() method from the GCMPubSub class is throwing InternalServerError again today. – Dan Ross Jul 03 '16 at 09:39
  • 1
    I am getting this using FCM. I noticed I could not subscribe to any topic from client side using FirebaseMessaging.getInstance().subscribeToTopic() following internalServerError in logs. though I can still retrieve a token. – Ramin Jul 03 '16 at 14:05