Twitter Hashtags and QR Codes
I spotted this poster today, encouraging people to search for the Twitter hashtag "#Transformers".
Wouldn't it make sense to use a QR code as well? That way people could quickly scan, and be taken straight to the discussion, rather than have to fire up Twitter and do a manual search.
As it happens, it's slightly tricky to make a QR code which searches for a Twitter hashtag.
There are two things to note:
- Twitter's search URLs are annoyingly different from every other search URL on the planet.
- You will need to take care of URL Encoding for special characters.
Building The Search Query
A typical Twitter search URL is
https://mobile.twitter.com/#!/search/
With the query at the end, so a search for "Transformers" would be
https://mobile.twitter.com/#!/search/Transformers
Encoding Correctly
Hash symbols (#) need to be URL Encoded. In this case, the hash becomes "%23"
https://mobile.twitter.com/#!/search/%23Transformers
However, there is a "gotcha". Because of the... special... way Twitter constructs its search URLs, we have to URL Encode the percentage sign! So, the "%" becomes "%25".
So, our final URL becomes
https://mobile.twitter.com/#!/search/%2523Transformers
Finally, if you want to use something like Google Charts to create your QR codes, you'll need the URL Encode all of the : / # ! and other special characters.
https://chart.googleapis.com/chart?chs=200x200&cht=qr&chl= https%3A%2F%2Fmobile.twitter.com%2F%23%21%2Fsearch%2F%2523Transformers
The Final Result
We end up with a QR code which can be scanned to take the user directly to the hashtag they are searching for,
Ryan Cullen says:
Why not drop the mobile bit, twitter will redirect to the most appropriate version for the device. Also you can use http://twitter.com/search?q= saving an character.
Terence Eden says:
Sadly, that doesn't work. Using ?q= gets redirected, but the search parameter is stripped off in the redirect.
Ryan Cullen says:
http://twitter.com/search?q=%2523test (in case it strips out has % 25 %23) worked fine.
Terence Eden says:
Interesting. It doesn't work for me. I wonder if it's because I'm signed in - or because I've got the new HTML5 experience?
Ryan Cullen says:
Full charts url if the image has gone: https://chart.googleapis.com/chart?chs=200x200&cht=qr&chl=http://twitter.com/search?q=%2523test
David Carrington says:
Maybe they thought about it and hit the same stumbling blocks as you. Your QR code URL doesn't work for me, leads me to the mobile twitter home screen.
Terence Eden says:
Mine or Ryan's?
If you can't use mine, and I can't use his, it looks like there's something seriously weird with how Twitter handles mobile searches and redirects.