A tool to find what Twitter hashtags you should use

I love Twitter. It’s a great tool to find current information for any topic of interest.  However, sometimes it feels like a message in a bottle endeavor. You post a tweet and it’s just gone. If you’re using twitter for your business you need to include a link sending people to your site. That’s probably how you got here today. 🙂

However, getting your tweet seen is the first step. There are three ways you tweet can be seen:

  1. Your followers will always see it
  2. It’s re-tweeted so other’s followers will see
  3. Someone finds it by twitter hashtag

The last one is the most difficult. What hashtags should you be using? You can guess, but I’m not a fan of that. I wrote a tool to show the most used twitter hashtags from your followers and who you follow.

The tool can be forked from GitHub repo named MyHashTags.

An example of the output for the people I follow from my account looks like this.

  • fsharp : 46
  • agile : 42
  • sxsw : 32
  • spsnh : 30
  • agileindia2014 : 23
  • icreatedthis : 23
  • pmot : 22
  • microsoftstudio : 21

As you can see, it’s pretty handy. If I wanted to increase exposure to my tweets, I could include several of the hashtags shown. Although it might be annoying if I included #SXSW on a topic that wasn’t about SXSW.

The code is fairly simple. I use the LinqToTwitter library. Then it’s just a matter of familiarizing yourself with the Twitter object model.

To get the list of users you’re interested in based on FriendshipType (followers or friends):

List<string> usernames =twitter.Friendship.FirstOrDefault(x => x.Type == friendshipType && x.ScreenName == username && x.Count == 100)
 .Users.Select(x => x.ScreenNameResponse)

Then you just need to loop through your friends and get their tweets:

List<Status> tweets = twitter.Status
.Where(x => x.Type == StatusType.User && x.ScreenName == username && x.Count == 100)

Lastly, loop through the tweets and get the hashtags, if any:

Dictionary<string,int> retval = new Dictionary<string, int>();
foreach (Status s in tweets)
 if (s.Entities != null && s.Entities.HashTagEntities != null && s.Entities.HashTagEntities.Count > 0)
  foreach (HashTagEntity ht in s.Entities.HashTagEntities)
   if (!retval.ContainsKey(ht.Tag.ToLower()))

The dictionary returns the hashtags and the number of times’ it’s been used.