С сегодняшнего дня я столкнулся с следующей проблемой, когда GCM «подписаться на темы». Nexus 6, Android 6.0.1, Google Play Services 9.0.83 Использование google-play-services: 8.3.0 в приложении.Подписаться на тему внезапно бросает "java.io.IOException: InternalServerError"
Шаг 1
Я следую документации от Google для получения токена через идентификатор экземпляра. После получения маркера я успешно подписался на тему «themes/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 Cloud Messaging (FCM) привело к нарушению изменений?
В настоящее время все мои клиентские приложения недоступны. Быстрая помощь действительно оценена.
Я видел ту же самую проблему с сегодняшнего утра. Не уверен, что не так, скажем, подпись com.google.android.gms недействительна. и имеют длинный SHA вниз –