Topics

Create Topics

You can create and manage topics from the Dashboard and HTTP API. To create topics from the dashboard navigate to the Topics page and click on the New Topic button.

Create Topic - GetSocial Dashboard

Topic creation needs the following information:

  1. Topic id: this is a unique id that you provide to identify the topic
  2. Name and Description: Name of the topic and description that you can make visible to your users. You can also enable users to search and discover topics by topic name. These can also be localized to 36+ supported languages.
  3. Icon: Topic icon is optional. Icon can be displayed with name and description in the app
  4. Permissions: with topic permissions you can define which users can post activity and interact with the topic. Interaction includes comments and reactions. You can enable everyone to post and interact, or only followers or a combination of one or more.
  5. Properties: additional metadata that you can add to the topic e.g custom data that might define UI elements for topic like topic color.

Get Topics

You can get a paginated list of all topics in your application:

1
2
3
4
5
6
7
8
val query = TopicsQuery.all()
val pagingQuery = PagingQuery(query)
Communities.getTopics(pagingQuery, { result: PagingResult<Topic> ->
    val topics = result.entries
    Log.d("Communities", "Topics: $topics")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get list of topics: $error")
})
1
2
3
4
5
6
7
let query = TopicsQuery.all()
let pagingQuery = TopicsPagingQuery(query)
Communities.topics(pagingQuery, success: { result in
    print("Topics: \(result.topics)")
}, failure: { error in
    print("Failed to get list of topics: \(error)")
})
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var query = TopicsQuery.All();
var pagingQuery = new PagingQuery<TopicsQuery>(query);

Communities.GetTopics(pagingQuery,
    (result) => {
        Debug.Log("Topics: " + result.Entries);
    },
    (error) => {
        Debug.Log("Failed to get list of topics, error: " + error);
    });
1
2
3
4
5
6
7
var query = TopicsQuery.all();
var pagingQuery = PagingQuery(query);
Communities.getTopics(pagingQuery)
    .then((result) {
        var topics = result.entries;
        print('Topics: $topics');
    }).catchError((error) => { print('Failed to get list of topics, error: $error') });
1
2
3
4
5
6
7
8
9
const query = TopicsQuery.all();
const pagingQuery = new PagingQuery(query);
Communities.getTopics(pagingQuery)
    .then((result) => {
        var topics = result.entries;
        console.log('Topics: ' + topics);
    }, (error) => {
        console.log('Failed to get list of topics, error: ' + error.message);        
    };

This method uses the PagingQuery concept that is used across our SDK. Read more about this.

Find Topics

You can also search topics by a query. Method returns all topics that contains the provided query as a substring in ID or Title. It is also case-insensitive.

1
2
3
4
5
6
7
8
9
val searchString = "cat"
val query = TopicsQuery.find(searchString)
val pagingQuery = PagingQuery(query)
Communities.getTopics(pagingQuery, { result: PagingResult<Topic> ->
    val topics = result.entries
    Log.d("Communities", "Topics contains $searchString: $topics")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get list of topics: $error")
})
1
2
3
4
5
6
7
8
let searchString = "cat"
let query = TopicsQuery.find(searchString)
let pagingQuery = TopicsPagingQuery(query)
Communities.topics(pagingQuery, success: { result in
    print("Topics containing \(searchString): \(result.topics)")
}, failure: { error in
    print("Failed to get list of topics: \(error)")
})
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var query = TopicsQuery.Find("cats");
var pagingQuery = new PagingQuery<TopicsQuery>(query);

Communities.GetTopics(pagingQuery,
    (result) => {
        Debug.Log("Topics including `cats`: " + result.Entries);
    },
    (error) => {
        Debug.Log("Failed to search for topics, error: " + error);
    });
1
2
3
4
5
6
7
8
var searchString = 'cat';
var query = TopicsQuery.find(searchString);
var pagingQuery = PagingQuery(query);
Communities.getTopics(pagingQuery)
    .then((result) {
        var topics = result.entries;
        print('Topics contain "cat": $topics');
    }).catchError((error) => { print('Failed to find topics, error: $error') });
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
const searchString = 'cat';
const query = TopicsQuery.find(searchString);
const pagingQuery = new PagingQuery(query);
Communities.getTopics(pagingQuery)
    .then((result) => {
        const topics = result.entries;
        console.log('Topics contain "cat": ' + topics);
    }, (error) => {
        console.log('Failed to find topics, error: ' + error.message);
    });

This method uses the PagingQuery concept that is used across our SDK. Read more about this.

Get Topics Count

Use the same query as you’re using to Get or Find topics.

1
2
3
4
5
6
7
val searchString = "cat"
val query = TopicsQuery.find(searchString)
Communities.getTopicsCount(query, { result: Int ->
    Log.d("Communities", "Topics count contains $searchString: $result")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get number of topics: $error")
})
1
2
3
4
5
6
7
let searchString = "cat"
let query = TopicsQuery.find(searchString)
Communities.topicsCount(query, success: { topicsCount in
    print("Topics count containing \(searchString): \(topicsCount)")
}, failure: { error in
    print("Failed to get number of topics: \(error)")
})
1
2
3
4
5
6
7
8
9
var query = TopicsQuery.Find("cats");

Communities.GetTopicsCount(query,
    (result) => {
        Debug.Log("Number of topics including `cats`: " + result);
    },
    (error) => {
        Debug.Log("Failed to get number of topics, error: " + error);
    });
1
2
3
4
5
6
var searchString = 'cat';
var query = TopicsQuery.find(searchString);
Communities.getTopicsCount(query)
    .then((result) {
        print('Topics count containing "cat": $result');
    }).catchError((error) => { print('Failed to get topics count, error: $error') });
1
2
3
4
5
6
7
8
const searchString = 'cat';
const query = TopicsQuery.find(searchString);
Communities.getTopicsCount(query)
    .then((result) => {
        console.log('Topics count containing "cat": ' + result);
    }, (error) => {
        console.log('Failed to get topics count, error: ' + error.message);
    });

Get Topic By ID

If you have just an ID of topic, you can get the topic object:

1
2
3
4
5
6
7
val topicId = "topic-id"

Communities.getTopic(topicId, { topic ->
    Log.d("Communities", "Topic with id $topicId: $topic")
}, { error ->
    Log.d("Communities", "Failed to get a topic: $error")
})
1
2
3
4
5
6
let topicId = "topic-id"
Communities.topic(topicId, success: { topic in
    print("Topic with id '\(topicId): \(topic)")
}, failure: { error in
    print("Failed to get topic: \(error)")
})
1
2
3
4
5
6
7
8
9
var topicId = "topic-id";

Communities.GetTopic(topicId,
    (result) => {
        Debug.Log("Topic: " + result);
    },
    (error) => {
        Debug.Log("Failed to get topic, error: " + error);
    });
1
2
3
4
5
var topicId = 'topic-id';
Communities.getTopic(topicId)
    .then((result) {
        print('Topic: $result');
    }).catchError((error) => { print('Failed to get topic, error: $error') });
1
2
3
4
5
6
7
const topicId = 'topic-id';
Communities.getTopic(topicId)
    .then((result) => {
        console.log('Topic: ' + result);
    }, (error) => {
        console.log('Failed to get topic, error: ' + error.message);
    });

Work With Topic Object

Learn what can you do with topic object in Android and iOS.

Follow

To follow topics use:

1
2
3
4
5
Communities.follow(FollowQuery.topics("dogs", "cats", "daily-challenges"), { topicsFollowing ->
    Log.d("Communities", "Successfully followed the topics. Now you follow $topicsFollowing topics!")
}, { error ->
    Log.d("Communities", "Failed to follow topics: $error")
})
1
2
3
4
5
Communities.follow(FollowQuery.topics(["dogs", "cats", "daily-challenges"]), success: { topicsFollowing in
    print("Successfully followed the topics. Now you follow \(topicsFollowing) topics!")
}, failure: { error in
    print("Failed to follow topics: \(error)")
})
1
2
3
4
5
6
7
Communities.Follow(FollowQuery.Topics("dogs", "cats", "daily-challenges"),
    (topicsFollowing) => {
        Debug.Log("Successfully followed the topics. Number of followed topics: " + topicsFollowing);
    },
    (error) => {
        Debug.Log("Failed to follow topics, error " + error);
    });
1
2
3
Communities.follow(FollowQuery.topics(['dogs', 'cats', 'daily-challenges']))
    .then((result) => print('Successfully followed the topics. Number of followed topics: $result'))
    .catchError((error) => print('Failed to follow topics, error: $error'));
1
2
Communities.follow(FollowQuery.topics(['dogs', 'cats', 'daily-challenges']))
    .then((result) => { console.log('Successfully followed the topics. Number of followed topics: ' + result); },(error) => { console.log('Failed to follow topics, error: ' + error.message); });

Unfollow

Unfollow works in the same way, as Follow, just use method unfollow:

1
2
3
4
5
Communities.unfollow(FollowQuery.topics("dogs", "cats", "daily-challenges"), { topicsFollowing ->
    Log.d("Communities", "Successully unfollowed the topics. Now you follow $topicsFollowing topics!")
}, { error ->
    Log.d("Communities", "Failed to follow topics: $error")
})
1
2
3
4
5
Communities.unfollow(FollowQuery.topics(["dogs", "cats", "daily-challenges"]), success: { topicsFollowing in
    print("Successully unfollowed the topics. Now you follow \(topicsFollowing) topics!")
}, failure: { error in
    print("Failed to follow topics: \(error)")
})
1
2
3
4
5
6
7
Communities.Unfollow(FollowQuery.Topics("dogs", "cats", "daily-challenges"),
    (topicsFollowing) => {
        Debug.Log("Successfully unfollowed the topics. Number of followed topics: " + topicsFollowing);
    },
    (error) => {
        Debug.Log("Failed to unfollow topics, error " + error);
    });
1
2
3
Communities.unfollow(FollowQuery.topics(['dogs', 'cats', 'daily-challenges']))
    .then((result) => print('Successfully unfollowed the topics. Number of followed topics: $result'))
    .catchError((error) => print('Failed to unfollow topics, error: $error'));
1
2
Communities.unfollow(FollowQuery.topics(['dogs', 'cats', 'daily-challenges']))
    .then((result) => { console.log('Successfully unfollowed the topics. Number of followed topics: ' + result); },(error) => { console.log('Failed to unfollow topics, error: ' + error.message); });

Is Following

To check if a certain user is following topics, use:

1
2
3
4
5
6
Communities.isFollowing(UserId.currentUser(), FollowQuery.topics("cats", "dogs"), { isFollowing ->
    Log.d("Communities", "Current user is following topic 'cats': ${isFollowing["cats"]}")
    Log.d("Communities", "Current user is following topic 'dogs': ${isFollowing["dogs"]}")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get followers of topic: $error")
})
1
2
3
4
5
6
Communities.isFollowing(UserId.currentUser(), query: FollowQuery.topics(["cats", "dogs"]), success: { isFollowing in
    print("Current user is following topic 'cats': \(isFollowing["cats"])")
    print("Current user is following topic 'dogs': \(isFollowing["dogs"])")
}, failure: { error in
    print("Failed to check followers of topics: \(error)")
})
1
2
3
4
5
6
7
8
9
Communities.IsFollowing(UserId.CurrentUser(), FollowQuery.Topics("cats", "dogs"),
    (result) => {
        Debug.Log("Current user is following topic 'cats': " + result["cats"]);
        Debug.Log("Current user is following topic 'dogs': " + result["dogs"]);
    },
    (error) => {
        Debug.Log("Failed to check followers of topics, error: " + error);
    }
);
1
2
3
4
5
6
7
8
Communities.isFollowing(UserId.currentUser(), FollowQuery.topics(['cats', 'dogs']))
    .then((result) {
        var catsFollowed = result['cats'];
        var dogsFollowed = result['cats'];
        print('Current user is following topic "cats": $catsFollowed');
        print('Current user is following topic "dogs": $dogsFollowed');
    })
    .catchError((error) => { print('Failed to check followers of topics, error: $error') });
1
2
3
4
5
6
7
8
9
Communities.isFollowing(UserId.currentUser(), FollowQuery.topics(['cats', 'dogs']))
    .then((result) => {
        var catsFollowed = result['cats'];
        var dogsFollowed = result['cats'];
        console.log('Current user is following topic "cats": ' + catsFollowed);
        console.log('Current user is following topic "dogs": ' + dogsFollowed);
    }, (error) => {
        console.log('Failed to check followers of topics, error: ' + error.message);
    });

First parameter is a user ID. We’re checking if current user is following some topics. The result is a map of String -> Boolean, where key is the id of the topic passed to FollowQuery and value is true, is user is following this topic or false otherwise.

Unexisting topics won’t be included in the result map.

Get Followers

To get followers of a topic:

1
2
3
4
5
6
7
8
val followersQuery = FollowersQuery.ofTopic("cats")
val pagingQuery = PagingQuery(followersQuery).withLimit(25)
Communities.getFollowers(pagingQuery, { result: PagingResult<User> ->
    val followersOfCatsTopic = result.entries
    Log.d("Communities", "Followers of topic 'cats': $followersOfCatsTopic")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get followers of the topic: $error")
})
1
2
3
4
5
6
7
8
9
let followersQuery = FollowersQuery.ofTopic("cats")
let pagingQuery = FollowersPagingQuery.init(followersQuery)
pagingQuery.limit = 25

Communities.followers(pagingQuery, success: { result in
    print("Followers of topic 'cats': \(result.followers)")
}, failure: { error in
    print("Failed to get followers of topic: \(error)")
})
1
2
3
4
5
6
7
8
9
var followersQuery = FollowersQuery.OfTopic("cats");
var pagingQuery = new PagingQuery<FollowersQuery>(followersQuery);
Communities.GetFollowers(pagingQuery,
    (result) => {
        Debug.Log("Followers of topic 'cats': " + result.Entries);
    },
    (error) => {
        Debug.Log("Failed to get followers of topic: " + error);
    });
1
2
3
4
5
6
7
8
9
var followersQuery = FollowersQuery.ofTopic('cats');
var pagingQuery = PagingQuery(followersQuery);
pagingQuery.limit = 25;
Communities.getFollowers(pagingQuery)
    .then((result) {
        var followers = result.entries;
        print('Followers of topic "cats": $followers');
    })
    .catchError((error) => { print('Failed to check followers of topic, error: $error') });
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
const followersQuery = FollowersQuery.ofTopic('cats');
const pagingQuery = new PagingQuery(followersQuery);
pagingQuery.limit = 25;
Communities.getFollowers(pagingQuery)
    .then((result) => {
        var followers = result.entries;
        console.log('Followers of topic "cats":' + followers);
    }, (error) => {
        console.log('Failed to check followers of topic, error: ' + error.message);
    });

This method uses the PagingQuery concept that is used across our SDK. Read more about this.

Followers Count

To get the followers count of a topic:

1
2
3
4
5
6
val topicsFollowers = FollowersQuery.ofTopic("level1")
Communities.getFollowersCount(topicsFollowers, { followersCount: Int ->
    Log.d("Communities", "Followers count of topic 'level1': $followersCount")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get followers of topic: $error")
})
1
2
3
4
5
6
let topicFollowers = FollowersQuery.ofTopic("level1")
Communities.followersCount(topicFollowers, success: { followersCount in
    print("Followers count of topic 'level1': \(followersCount)")
}, failure: { error in
    print("Failed to get followers count of topic: \(error)")
})
1
2
3
4
5
6
7
8
var topicFollowers = FollowersQuery.OfTopic("cats");
Communities.GetFollowersCount(topicFollowers,
    (result) => {
        Debug.Log("Followers count of topic 'cats': " + result);
    },
    (error) => {
        Debug.Log("Failed to get followers count of topic: " + error);
    });
1
2
3
4
5
6
var topicFollowers = FollowersQuery.ofTopic('level1');
Communities.getFollowersCount(topicFollowers)
    .then((result) {
        print('Followers count of topic "level1": $result');
    })
    .catchError((error) => { print('Failed to check followers count of topic, error: $error') });
1
2
3
4
5
6
7
const topicFollowers = FollowersQuery.ofTopic('level1');
Communities.getFollowersCount(topicFollowers)
    .then((result) => {
        console.log('Followers count of topic "level1": ' + result);
    }, (error) => {
        console.log('Failed to check followers count of topic, error: ' + error.message);    
    });

Get Following Topics

You can also get all the topics that are followed by a certain user:

1
2
3
4
5
6
7
8
val query = TopicsQuery.followedBy(UserId.currentUser())
val pagingQuery = PagingQuery(query)
Communities.getTopics(pagingQuery, { result: PagingResult<Topic> ->
    val topics = result.entries
    Log.d("Communities", "Topics followed by current user: $topics")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get list of topics: $error")
})
1
2
3
4
5
6
7
let query = TopicsQuery.followedBy(UserId.currentUser())
let pagingQuery = TopicsPagingQuery(query)
Communities.topics(pagingQuery, success: { result in
    print("Topics followed by current user: \(result.topics)")
}, failure: { error in
    print("Failed to get list of topics: \(error)")
})
1
2
3
4
5
6
7
8
9
var query = TopicsQuery.FollowedBy(UserId.CurrentUser());
var pagingQuery = new PagingQuery<TopicsQuery(query);
Communities.GetTopics(pagingQuery,
    (result) => {
        Debug.Log("Topics followed by current user: " + result.Entries);
    },
    (error) => {
        Debug.Log("Failed to get list of topics: " + error);
    });
1
2
3
4
5
6
7
var query = TopicsQuery.all().followedBy(UserId.currentUser());
var pagingQuery = PagingQuery(query);
Communities.getTopics(pagingQuery)
    .then((result) {
        var topics = result.entries;
        print('Topics followed by current user: $topics');
    }).catchError((error) => { print('Failed to get list of topics, error: $error') });
1
2
3
4
5
6
7
8
9
const query = TopicsQuery.all().followedBy(UserId.currentUser());
const pagingQuery = new PagingQuery(query);
Communities.getTopics(pagingQuery)
    .then((result) {
        var topics = result.entries;
        console.log('Topics followed by current user: ' + topics);
    }, (error) => {
        console.log('Failed to get list of topics, error: $error');
    });

Topic Feed

Every topic has its own feed where users can interact with each other and see the topic’s post on their timeline.

In addition to this, you can also post announcements on specific topic from the dashboard.

Learn what how can you Load Content from a Topic Feed or Post in a Topic feed.

Give us your feedback! Was this article helpful?

😀 🙁