Skip to content

Tags

Create Tags

Tags (or Hashtags) are automatically created when activities are posted.
Tags are extracted from the activity content by finding all strings started with #.
We stored them internally normalized without the # symbol and all lowercase, therefore any search will be be case-insensitive.

Get Tags

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

val query = TagsQuery.all()
val pagingQuery = PagingQuery(query)
Communities.getTags(pagingQuery, { result: PagingResult<Tag> ->
    val tags = result.entries
    Log.d("Communities", "Tags: $tags")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get list of tags: $error")
})
let query = TagsQuery.all()
let pagingQuery = TagsPagingQuery(query)
Communities.tags(pagingQuery, success: { result in
    print("Tags: \(result.tags)")
}, failure: { error in
    print("Failed to get list of tags: \(error)")
})
TagsQuery query = TagsQuery.all();
Communities.getTags(PagingQuery(query)).then((result) {
    print('Tags: ' + result.entries);
}).catchError((error) {
    print('Failed to get list of tags, error: ' + error);
});
const query = TagsQuery.all();
const pagingQuery = new PagingQuery(query);
Communities.getTags(pagingQuery)
    .then((result) => console.log('Tags:', result.entries))
    .catch((error) => console.error('Failed to get list of tags:', error));
const query = GetSocialSDK.TagsQuery.all();
GetSocialSDK.Communities.getTags(new GetSocialSDK.PagingQuery(query))
    .then((result) => console.log('Tags:', result.entries))
    .catch((error) => console.error('Failed to get list of tags:', error));

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

Find Tags

You can also search tags by a substring, trending or tags followed by a specific user.

val searchString = "cat"
val query = TagsQuery.find(searchString)
val pagingQuery = PagingQuery(query)
Communities.getTags(pagingQuery, { result: PagingResult<Tag> ->
    val tags = result.entries
    Log.d("Communities", "Tags contains $searchString: $tags")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get list of tags: $error")
})
let searchString = "cat"
let query = TagsQuery.find(searchString)
let pagingQuery = TagsPagingQuery(query)
Communities.tags(pagingQuery, success: { result in
    print("Tags containing \(searchString): \(result.tags)")
}, failure: { error in
    print("Failed to get list of tags: \(error)")
})
String searchString = 'cat';
TagsQuery query = TagsQuery.find(searchText)
Communities.getTags(PagingQuery(query)).then((result) {
    print('Tags containing ' + searchString + ': ' + result.entries);
}).catchError((error) {
    print('Failed to get list of tags, error: ' + error);
});
const searchString = 'cat';
const query = TagsQuery.find(searchString);
const pagingQuery = new PagingQuery(query);
Communities.getTags(pagingQuery)
    .then((result) => {
        console.log(`Tags containing ${searchString}:`, result.entries);
    })
    .catch((error) => console.error('Failed to get list of tags:', error));
const searchString = 'cat';
const query = GetSocialSDK.TagsQuery.search(searchString);
GetSocialSDK.Communities.getTags(new GetSocialSDK.PagingQuery(query))
    .then((result) => {
        console.log(`Tags containing ${searchString}:`, result.entries);
    })
    .catch((error) => console.error('Failed to get list of tags:', error));

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

It is possible to get trending tags:

val query = TagsQuery.find("cats").onlyTrending(true)
let query = TagsQuery.find("cats").onlyTrending(true)
TagsQuery query = TagsQuery.find('cats').onlyTrending(true);
const query = TagsQuery.find('cats').onlyTrending(true);
const query = GetSocialSDK.TagsQuery.search('cats').onlyTrending(true);

Get Tags Count

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

val searchString = "cat"
val query = TagsQuery.find(searchString)
Communities.getTagsCount(query, { result: Int ->
    Log.d("Communities", "Tags count contains $searchString: $result")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get number of tags: $error")
})
let searchString = "cat"
let query = TagsQuery.find(searchString)
Communities.tagsCount(query, success: { tagsCount in
    print("Tags count containing \(searchString): \(tagsCount)")
}, failure: { error in
    print("Failed to get number of tags: \(error)")
})
String searchString = 'cat';
TagsQuery query = TagsQuery.find(searchText)
Communities.getTagsCount(query).then((result) {
    print('Number of tags including cats: ' + result.entries);
}).catchError((error) {
    print('Failed to get number of tags, error: ' + error);
});
const searchString = 'cat';
const query = TagsQuery.find(searchString);
Communities.getTagsCount(query)
    .then((count) => {
        console.log(`Tags count containing ${searchString}: ${count}`);
    })
    .catch((error) => console.error('Failed to get number of tags:', error));
const searchString = 'cat';
const query = GetSocialSDK.TagsQuery.search(searchString);
GetSocialSDK.Communities.getTagsCount(query)
    .then((count) => {
        console.log(`Tags count containing ${searchString}: ${count}`);
    })
    .catch((error) => console.error('Failed to get number of tags:', error));

Follow

To follow tags use:

Communities.follow(FollowQuery.tags("dogs", "cats", "daily-challenges"), { tagsFollowing ->
    Log.d("Communities", "Successfully followed the Tags. Now you follow $tagsFollowing Tags!")
}, { error ->
    Log.d("Communities", "Failed to follow Tags: $error")
})
Communities.follow(FollowQuery.tags(["dogs", "cats", "daily-challenges"]), success: { tagsFollowing in
    print("Successfully followed the Tags. Now you follow \(tagsFollowing) Tags!")
}, failure: { error in
    print("Failed to follow Tags: \(error)")
})
Communities.follow(FollowQuery.tags(['dogs', 'cats', 'daily-challenges']))
    .then((result) => print('Successfully followed the tags. Number of followed tags: $result'))
    .catchError((error) => print('Failed to follow tags, error: $error'));
Communities.follow(FollowQuery.tags(['dogs', 'cats', 'daily-challenges']))
    .then((tagsFollowing) => {
        console.log(`Successfully followed the Tags. Now you follow ${tagsFollowing} Tags!`);
    })
    .catch((error) => console.error('Failed to follow Tags:', error));
GetSocialSDK.Communities.follow(GetSocialSDK.FollowQuery.tags(['dogs', 'cats', 'daily-challenges']))
    .then((tagsFollowing) => {
        console.log(`Successfully followed the Tags. Now you follow ${tagsFollowing} Tags!`);
    })
    .catch((error) => console.error('Failed to follow Tags:', error));

Unfollow

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

Communities.unfollow(FollowQuery.tags("dogs", "cats", "daily-challenges"), { tagsFollowing ->
    Log.d("Communities", "Successully unfollowed the Tags. Now you follow $tagsFollowing Tags!")
}, { error ->
    Log.d("Communities", "Failed to unfollow Tags: $error")
})
Communities.unfollow(FollowQuery.tags(["dogs", "cats", "daily-challenges"]), success: { tagsFollowing in
    print("Successully unfollowed the Tags. Now you follow \(tagsFollowing) Tags!")
}, failure: { error in
    print("Failed to unfollow Tags: \(error)")
})
Communities.unfollow(FollowQuery.tags(['dogs', 'cats', 'daily-challenges']))
    .then((result) => print('Successfully unfollowed the tags. Number of followed tags: $result'))
    .catchError((error) => print('Failed to unfollowed tags, error: $error'));
Communities.unfollow(FollowQuery.tags(['dogs', 'cats', 'daily-challenges']))
    .then((tagsFollowing) => {
        console.log(`Successfully unfollowed the Tags. Now you follow ${tagsFollowing} Tags!`);
    })
    .catch((error) => console.error('Failed to unfollow Tags:', error));
GetSocialSDK.Communities.unfollow(GetSocialSDK.FollowQuery.tags(['dogs', 'cats', 'daily-challenges']))
    .then((tagsFollowing) => {
        console.log(`Successfully unfollowed the Tags. Now you follow ${tagsFollowing} Tags!`);
    })
    .catch((error) => console.error('Failed to unfollow Tags:', error));

Is Following

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

Communities.isFollowing(UserId.currentUser(), FollowQuery.tags("cats", "dogs"), { isFollowing ->
    Log.d("Communities", "Current user is following Tags 'cats': ${isFollowing["cats"]}")
    Log.d("Communities", "Current user is following Tags 'dogs': ${isFollowing["dogs"]}")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get followers of Tags: $error")
})
Communities.isFollowing(UserId.currentUser(), query: FollowQuery.tags(["cats", "dogs"]), success: { isFollowing in
    print("Current user is following Tags 'cats': \(isFollowing["cats"])")
    print("Current user is following Tags 'dogs': \(isFollowing["dogs"])")
}, failure: { error in
    print("Failed to check followers of Tags: \(error)")
})
Communities.isFollowing(UserId.currentUser(), FollowQuery.tags(['cats', 'dogs']))
    .then((result) {
        var catsFollowed = result['cats'];
        var dogsFollowed = result['dogs'];
        print('Current user is following tags "cats": $catsFollowed');
        print('Current user is following tags "dogs": $dogsFollowed');
    })
    .catchError((error) => { print('Failed to check followers of tags, error: $error') });
Communities.isFollowing(UserId.currentUser(), FollowQuery.tags(['cats', 'dogs']))
    .then((isFollowing) => {
        console.log(`You're ${isFollowing.cats ? '':'not '}following the tag 'cats'`);
        console.log(`You're ${isFollowing.dogs ? '':'not '}following the tag 'dogs'`);
    })
    .catch((error) => console.error('Failed to check followers of Tags:', error));
GetSocialSDK.Communities.isFollowing(GetSocialSDK.UserId.currentUser(), GetSocialSDK.FollowQuery.tags(['cats', 'dogs']))
    .then((isFollowing) => {
        console.log(`You're ${isFollowing.cats ? '':'not '}following the tag 'cats'`);
        console.log(`You're ${isFollowing.dogs ? '':'not '}following the tag 'dogs'`);
    })
    .catch((error) => console.error('Failed to check followers of Tags:', error));

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

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

Get Followers

To get followers of a Tags:

val followersQuery = FollowersQuery.ofTag("cats")
val pagingQuery = PagingQuery(followersQuery).withLimit(25)
Communities.getFollowers(pagingQuery, { result: PagingResult<User> ->
    val followersOfCatsTag = result.entries
    Log.d("Communities", "Followers of Tags 'cats': $followersOfCatsTag")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get followers of the Tags: $error")
})
let followersQuery = FollowersQuery.ofTag("cats")
let pagingQuery = FollowersPagingQuery.init(followersQuery)
pagingQuery.limit = 25

Communities.followers(pagingQuery, success: { result in
    print("Followers of Tags 'cats': \(result.followers)")
}, failure: { error in
    print("Failed to get followers of Tags: \(error)")
})
var followersQuery = FollowersQuery.ofTag('cats');
var pagingQuery = PagingQuery(followersQuery);
pagingQuery.limit = 25;
Communities.getFollowers(pagingQuery)
    .then((result) {
        var followers = result.entries;
        print('Followers of tag "cats": $followers');
    })
    .catchError((error) => { print('Failed to check followers of tag, error: $error') });
const followersQuery = FollowersQuery.ofTag('cats');
const pagingQuery = new PagingQuery(followersQuery);
pagingQuery.limit = 25;

Communities.getFollowers(pagingQuery)
    .then((result) => {
        console.log('Followers of Tag "cats":', result.entries);
    })
    .catch((error) => console.error('Failed to get followers of Tags:', error));
const followersQuery = GetSocialSDK.FollowersQuery.ofTag('cats');
const query = new GetSocialSDK.PagingQuery(followersQuery);
query.limit = 25;

GetSocialSDK.Communities.getFollowers(query)
    .then((result) => {
        console.log('Followers of Tag "cats":', result.entries);
    })
    .catch((error) => console.error('Failed to get followers of Tags:', error));

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 tag:

val tagsFollowers = FollowersQuery.ofTag("level1")
Communities.getFollowersCount(tagsFollowers, { followersCount: Int ->
    Log.d("Communities", "Followers count of Tags 'level1': $followersCount")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get followers of Tags: $error")
})
let tagFollowers = FollowersQuery.ofTag("level1")
Communities.followersCount(tagFollowers, success: { followersCount in
    print("Followers count of Tags 'level1': \(followersCount)")
}, failure: { error in
    print("Failed to get followers count of Tags: \(error)")
})
var tagFollowers = FollowersQuery.ofTag('level1');
Communities.getFollowersCount(tagFollowers)
    .then((result) {
        print('Followers count of tag "level1": $result');
    })
    .catchError((error) => { print('Failed to check followers count of tag, error: $error') });
const tagFollowers = FollowersQuery.ofTag('level1');

Communities.getFollowersCount(tagFollowers)
    .then((count) => {
        console.log(`Followers count of Tags 'level1': ${count}`);
    })
    .catch((error) => console.error('Failed to get followers count of Tags:', error));
const tagFollowers = GetSocialSDK.FollowersQuery.ofTag('level1');

GetSocialSDK.Communities.getFollowersCount(tagFollowers)
    .then((count) => {
        console.log(`Followers count of Tags 'level1': ${count}`);
    })
    .catch((error) => console.error('Failed to get followers count of Tags:', error));

Get Following Tags

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

val query = TagsQuery.followedBy(UserId.currentUser())
val pagingQuery = PagingQuery(query)
Communities.getTags(pagingQuery, { result: PagingResult<Tag> ->
    val tags = result.entries
    Log.d("Communities", "Tags followed by current user: $tags")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get list of Tags: $error")
})
let query = TagsQuery.followedBy(UserId.currentUser())
let pagingQuery = TagsPagingQuery(query)
Communities.tags(pagingQuery, success: { result in
    print("Tags followed by current user: \(result.tags)")
}, failure: { error in
    print("Failed to get list of Tags: \(error)")
})
var query = TagsQuery.all().followedBy(UserId.currentUser());
var pagingQuery = PagingQuery(query);
Communities.getTags(pagingQuery)
    .then((result) {
        var tags = result.entries;
        print('Tags followed by current user: $tags');
    }).catchError((error) => { print('Failed to get list of tags, error: $error') });
const query = TagsQuery.followedBy(UserId.currentUser());
const pagingQuery = new PagingQuery(query);
Communities.getTags(pagingQuery)
    .then((result) => {
        console.log('Tags followed by current user:', result.entries);
    })
    .catch((error) => console.error('Failed to get list of Tags', error));
const query = GetSocialSDK.TagsQuery.all().followedBy(GetSocialSDK.UserId.currentUser());
GetSocialSDK.Communities.getTags(new GetSocialSDK.PagingQuery(query))
    .then((result) => {
        console.log('Tags followed by current user:', result.entries);
    })
    .catch((error) => console.error('Failed to get list of Tags', error));

Activities with Tags

You can also filter all activities with a given Hashtag.

Give us your feedback! Was this article helpful?

😀 🙁