İstemci uygulamasını sunucudan veya istemciden bir konuya abone yapabilirsiniz:
Sunucuda, FCM konu aboneliği sunucu API'sini veya Firebase Admin SDK kullanarak.
İstemcide, uygulamanızdaki istemci tarafı API'yi kullanarak.
Konu aboneliği sunucu API'sini kullanarak konu aboneliklerini yönetme
Bir FCM kaydını bir konuya abone yapmak için kayıt kimliğini (Firebase yükleme kimliği veya FCM kayıt jetonu) gösterildiği gibi FCM konu aboneliği sunucu API'sine iletin.
REST
POST https://fcm.googleapis.com/v1/projects/${PROJECT_ID}/registrations/${REGISTRATION_ID}/topicSubscriptions?topic_name=${TOPIC_NAME}
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{}
curl komutu:
curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{}'
https://fcm.googleapis.com/v1/projects/${PROJECT_ID}/registrations/${REGISTRATION_ID}/topicSubscriptions?topic_name=${TOPIC_NAME}
İşlem başarılı olursa HTTP v1 API yanıtı, kaynak adını, konu adını ve zaman damgasını içeren bir JSON nesnesi olur.
{
"topic_name": "${TOPIC_NAME}",
"create_time": "2026-01-15T01:30:15.01Z"
}
FCM V1 konu abonelikleri API'si, DELETE isteği aracılığıyla bir jetonun konu aboneliğinden çıkmanıza da olanak tanır:
REST
DELETE https://fcm.googleapis.com/v1/projects/${PROJECT_ID}/registrations/${REGISTRATION_ID}/topicSubscriptions/${TOPIC_NAME}
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{}
curl komutu:
curl -X DELETE -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{}'
https://fcm.googleapis.com/v1/projects/${PROJECT_ID}/registrations/${REGISTRATION_ID}/topicSubscriptions/${TOPIC_NAME}
Bir kayıt kimliğinin konu aboneliklerini GET isteğiyle de listeleyebilirsiniz:
REST
GET https://fcm.googleapis.com/v1/projects/${PROJECT_ID}/registrations/${REGISTRATION_ID}/topicSubscriptions
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
curl komutu:
curl -X GET -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json"
https://fcm.googleapis.com/v1/projects/${PROJECT_ID}/registrations/${REGISTRATION_ID}/topicSubscriptions
İşlem başarılı olduğunda HTTP v1 API yanıtı, konu aboneliklerinin listesini içeren bir JSON nesnesi olur.
{
"topic_subscriptions": [
{
"topic_name": "${TOPIC_NAME1}",
"create_time": "2026-01-15T01:30:15.01Z"
},
{
"topic_name": "${TOPIC_NAME2}",
"create_time": "2026-01-16T02:40:17.01Z"
},
...
]
}
Admin SDK'yı kullanarak konu aboneliklerini yönetme
Firebase Admin SDK, sunucu tarafında temel konu yönetimi görevlerini gerçekleştirmenize olanak tanır. Kayıt jetonlarını kullanarak sunucu mantığıyla istemci uygulama örneklerine toplu olarak abone olabilir ve abonelikten çıkabilirsiniz.
İstemci uygulama örneklerini mevcut herhangi bir konuya abone edebilir veya yeni bir konu oluşturabilirsiniz. API'yi kullanarak bir istemci uygulamasını yeni bir konuya (Firebase projenizde henüz mevcut olmayan bir konu) abone yaptığınızda, FCM'de bu ada sahip yeni bir konu oluşturulur ve herhangi bir istemci daha sonra bu konuya abone olabilir.
İlgili cihazları bir konuya abone yapmak için Firebase Admin SDK abonelik yöntemine kayıt jetonlarının listesini iletebilirsiniz:
Node.js
// These registration tokens come from the client FCM SDKs.
const registrationTokens = [
'YOUR_REGISTRATION_TOKEN_1',
// ...
'YOUR_REGISTRATION_TOKEN_n'
];
// Subscribe the devices corresponding to the registration tokens to the
// topic.
getMessaging().subscribeToTopic(registrationTokens, topic)
.then((response) => {
// See the MessagingTopicManagementResponse reference documentation
// for the contents of response.
console.log('Successfully subscribed to topic:', response);
})
.catch((error) => {
console.log('Error subscribing to topic:', error);
});
Java
// These registration tokens come from the client FCM SDKs.
List<String> registrationTokens = Arrays.asList(
"YOUR_REGISTRATION_TOKEN_1",
// ...
"YOUR_REGISTRATION_TOKEN_n"
);
// Subscribe the devices corresponding to the registration tokens to the
// topic.
TopicManagementResponse response = FirebaseMessaging.getInstance().subscribeToTopicAsync(
registrationTokens, topic).get();
// See the TopicManagementResponse reference documentation
// for the contents of response.
System.out.println(response.getSuccessCount() + " tokens were subscribed successfully");
Python
# These registration tokens come from the client FCM SDKs.
registration_tokens = [
'YOUR_REGISTRATION_TOKEN_1',
# ...
'YOUR_REGISTRATION_TOKEN_n',
]
# Subscribe the devices corresponding to the registration tokens to the
# topic.
response = messaging.subscribe_to_topic(registration_tokens, topic)
# See the TopicManagementResponse reference documentation
# for the contents of response.
print(response.success_count, 'tokens were subscribed successfully')
Go
// These registration tokens come from the client FCM SDKs.
registrationTokens := []string{
"YOUR_REGISTRATION_TOKEN_1",
// ...
"YOUR_REGISTRATION_TOKEN_n",
}
// Subscribe the devices corresponding to the registration tokens to the
// topic.
response, err := client.SubscribeToTopic(ctx, registrationTokens, topic)
if err != nil {
log.Fatalln(err)
}
// See the TopicManagementResponse reference documentation
// for the contents of response.
fmt.Println(response.SuccessCount, "tokens were subscribed successfully")
C#
// These registration tokens come from the client FCM SDKs.
var registrationTokens = new List<string>()
{
"YOUR_REGISTRATION_TOKEN_1",
// ...
"YOUR_REGISTRATION_TOKEN_n",
};
// Subscribe the devices corresponding to the registration tokens to the
// topic
var response = await FirebaseMessaging.DefaultInstance.SubscribeToTopicAsync(
registrationTokens, topic);
// See the TopicManagementResponse reference documentation
// for the contents of response.
Console.WriteLine($"{response.SuccessCount} tokens were subscribed successfully");
Firebase Admin SDK, kayıt jetonlarını uygun yönteme ileterek cihazların bir konunun e-posta listesinden çıkmasını da sağlar:
Node.js
// These registration tokens come from the client FCM SDKs.
const registrationTokens = [
'YOUR_REGISTRATION_TOKEN_1',
// ...
'YOUR_REGISTRATION_TOKEN_n'
];
// Unsubscribe the devices corresponding to the registration tokens from
// the topic.
getMessaging().unsubscribeFromTopic(registrationTokens, topic)
.then((response) => {
// See the MessagingTopicManagementResponse reference documentation
// for the contents of response.
console.log('Successfully unsubscribed from topic:', response);
})
.catch((error) => {
console.log('Error unsubscribing from topic:', error);
});
Java
// These registration tokens come from the client FCM SDKs.
List<String> registrationTokens = Arrays.asList(
"YOUR_REGISTRATION_TOKEN_1",
// ...
"YOUR_REGISTRATION_TOKEN_n"
);
// Unsubscribe the devices corresponding to the registration tokens from
// the topic.
TopicManagementResponse response = FirebaseMessaging.getInstance().unsubscribeFromTopicAsync(
registrationTokens, topic).get();
// See the TopicManagementResponse reference documentation
// for the contents of response.
System.out.println(response.getSuccessCount() + " tokens were unsubscribed successfully");
Python
# These registration tokens come from the client FCM SDKs.
registration_tokens = [
'YOUR_REGISTRATION_TOKEN_1',
# ...
'YOUR_REGISTRATION_TOKEN_n',
]
# Unubscribe the devices corresponding to the registration tokens from the
# topic.
response = messaging.unsubscribe_from_topic(registration_tokens, topic)
# See the TopicManagementResponse reference documentation
# for the contents of response.
print(response.success_count, 'tokens were unsubscribed successfully')
Go
// These registration tokens come from the client FCM SDKs.
registrationTokens := []string{
"YOUR_REGISTRATION_TOKEN_1",
// ...
"YOUR_REGISTRATION_TOKEN_n",
}
// Unsubscribe the devices corresponding to the registration tokens from
// the topic.
response, err := client.UnsubscribeFromTopic(ctx, registrationTokens, topic)
if err != nil {
log.Fatalln(err)
}
// See the TopicManagementResponse reference documentation
// for the contents of response.
fmt.Println(response.SuccessCount, "tokens were unsubscribed successfully")
C#
// These registration tokens come from the client FCM SDKs.
var registrationTokens = new List<string>()
{
"YOUR_REGISTRATION_TOKEN_1",
// ...
"YOUR_REGISTRATION_TOKEN_n",
};
// Unsubscribe the devices corresponding to the registration tokens from the
// topic
var response = await FirebaseMessaging.DefaultInstance.UnsubscribeFromTopicAsync(
registrationTokens, topic);
// See the TopicManagementResponse reference documentation
// for the contents of response.
Console.WriteLine($"{response.SuccessCount} tokens were unsubscribed successfully");
subscribeToTopic() ve unsubscribeFromTopic() yöntemleri, FCM tarafından gönderilen yanıtı içeren bir nesne döndürür. Dönüş türü, istekte belirtilen kayıt jetonlarının sayısından bağımsız olarak aynı biçime sahiptir.
Hata durumunda (kimlik doğrulama hataları, geçersiz jeton veya konu vb.) bu yöntemler hata döndürür. Açıklamalar ve çözüm adımları da dahil olmak üzere hata kodlarının tam listesi için Firebase Admin SDK Hataları başlıklı makaleyi inceleyin.
Konu aboneliklerini istemci uygulamanızdan yönetme
İstemci uygulama örnekleri, Firebase SDK'ları aracılığıyla doğrudan uygulamanızdan konulara abone olabilir veya abonelikten çıkabilir. Aboneliğin başarılı olmasını sağlamak için ilk başarısızlık durumunda FCM'ın yeniden deneme yaptığını unutmayın.
Platformunuzu seçin:
Android
İstemci uygulamaları, mevcut herhangi bir konuya abone olabilir veya yeni bir konu oluşturabilir. İstemci uygulaması yeni bir konu adına (Firebase projenizde henüz mevcut olmayan bir konu) abone olduğunda, FCM içinde bu ada sahip yeni bir konu oluşturulur ve herhangi bir istemci daha sonra bu konuya abone olabilir.
Bir konuya abone olmak için istemci uygulaması, FCM konu adıyla Firebase Cloud Messaging
subscribeToTopic() yöntemini çağırır. Bu yöntem, aboneliğin başarılı olup olmadığını belirlemek için bir tamamlama dinleyicisi tarafından kullanılabilecek bir Task döndürür:
Kotlin
Firebase.messaging.subscribeToTopic("weather") .addOnCompleteListener { task -> var msg = "Subscribed" if (!task.isSuccessful) { msg = "Subscribe failed" } Log.d(TAG, msg) Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show() }
Java
FirebaseMessaging.getInstance().subscribeToTopic("weather") .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { String msg = "Subscribed"; if (!task.isSuccessful()) { msg = "Subscribe failed"; } Log.d(TAG, msg); Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); } });
Abonelikten çıkmak için istemci uygulaması, konu adıyla Firebase Cloud Messaging unsubscribeFromTopic()
yöntemini çağırır.
iOS
İstemci uygulamaları, mevcut herhangi bir konuya abone olabilir veya yeni bir konu oluşturabilir. İstemci uygulaması yeni bir konu adına (Firebase projenizde henüz mevcut olmayan bir konu) abone olduğunda, FCM içinde bu ada sahip yeni bir konu oluşturulur ve herhangi bir istemci daha sonra bu konuya abone olabilir.
Bir konuya abone olmak için uygulamanızın ana iş parçacığından abonelik yöntemini çağırın (FCM, iş parçacığı açısından güvenli değildir). Abonelik isteği ilk denemede başarısız olursa FCM otomatik olarak yeniden dener. Aboneliğin tamamlanamadığı durumlarda abonelik, tamamlama işleyicisinde yakalayabileceğiniz bir hata verir:
Swift
Messaging.messaging().subscribe(toTopic: "weather") { error in
print("Subscribed to weather topic")
}Objective-C
[[FIRMessaging messaging] subscribeToTopic:@"weather" completion:^(NSError * _Nullable error) { NSLog(@"Subscribed to weather topic"); }];
Bu çağrı, FCM arka ucuna asenkron bir istek gönderir ve istemciyi belirtilen konuya abone yapar. subscribeToTopic:topic yöntemini çağırmadan önce
istemci uygulama örneğinin
geri çağırma işlevididReceiveRegistrationToken aracılığıyla bir kayıt jetonu aldığından emin olun.
Uygulama her başlatıldığında FCM, istenen tüm konulara abone olunduğundan emin olur. Abonelikten çıkmak için unsubscribeFromTopic:topic işlevini çağırın. FCM, arka planda konunun aboneliğinden çıkar.
C++
Bir konuya abone olmak için uygulamanızdan ::firebase::messaging::Subscribe
yöntemini çağırın. Bu işlem, FCM arka ucuna asenkron bir istek gönderir ve istemciyi belirtilen konuya abone yapar.
::firebase::messaging::Subscribe("example");
Abonelik isteği başlangıçta başarısız olursa FCM, konuya başarıyla abone olana kadar yeniden dener. Uygulama her başlatıldığında FCM, istenen tüm konulara abone olunduğundan emin olur.
Abonelikten çıkmak için ::firebase::messaging::Unsubscribe işlevini çağırın. FCM, arka planda konunun aboneliğinden çıkar.
Unity
Bir konuya abone olmak için uygulamanızdan Firebase.Messaging.FirebaseMessaging.Subscribe yöntemini çağırın. Bu işlem, FCM arka ucuna asenkron bir istek gönderir ve istemciyi belirtilen konuya abone yapar.
Firebase.Messaging.FirebaseMessaging.Subscribe("/topics/example");
Abonelik isteği başlangıçta başarısız olursa FCM, konuya başarıyla abone olana kadar yeniden dener. Uygulama her başlatıldığında FCM, istenen tüm konulara abone olunduğundan emin olur.
Abonelikten çıkmak için Firebase.Messaging.FirebaseMessaging.Unsubscribe işlevini çağırın. FCM, arka planda konunun aboneliğinden çıkar.
Eski Sunucu Tarafı Konu Yönetimi (Desteği Sonlandırıldı)
Örnek kimliklerinin ne olduğunu öğrenmek için Örnek Kimliği sayfasını ziyaret edin. Desteği sonlandırılan uç noktalar hakkında ayrıntılı bilgi için Örnek Kimliği API Referansları'na bakın.
FID veya jeton değişikliğinde konu aboneliklerini yönetme
Bir uygulamanın FID'si (Firebase Kurulum Kimliği) veya FCM jetonu değiştiğinde, eski FID veya jetonla ilişkili konu abonelikleri taşınmaz ve sonuç olarak yeni tanımlayıcının konu aboneliği olmaz. Genellikle uygulama güncellemeleri veya jeton yenilemeleri sırasında jeton değişmez. Jeton değişikliğinin en yaygın nedeni, FID silme/rotasyonudur. Bu durum, Firebase kurulum kimliği yaşam döngüsünü izleme bölümündeki adımlar uygulanarak izlenebilir.
FID veya jeton değişikliklerinde konu aboneliklerini korumak istiyorsanız istemcide veya arka uçta konu aboneliği verilerini yedeklemeniz ve yeni tanımlayıcıyı, uygulama örneğinin daha önce abone olduğu konulara abone etmeniz gerekir. Firebase, bu abonelikleri izlemek veya taşımak için otomatik özellikler ya da işlevler sunmaz. Bu, uygulamanızda ve arka ucunuzda manuel olarak uygulamanız gereken bir görevdir.