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

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

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)

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

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

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 follow 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 follow 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)")
})

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

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

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

Activities with Tags

You can also filter all activities with a given Hashtag.

Give us your feedback! Was this article helpful?

😀 🙁