Free tech support / small logo


Can I have a Twitter search box / button on my site?

I think that Twitter is pretty darn cool and would really like to be able to add a Twitter search box to my web site. In fact, I'd love to have some buttons that are pre-defined searches, like for the name of the latest movie in the theater or a celebrity too. Are those possible? I haven't seen anyone do anything like that before...


Dave's Answer:

Everything's doable! The question is "how much of a nightmare would it be to add this?" and the good news is that the Twitter search system is incredibly easy to work with, and, better, it also has a sophisticated search engine so you can refine those buttons to filter out false matches (imagine the tons of false hits you'd get from the movie "Push", for example).

It all starts with search.twitter.com and a bit of HTML knowledge.

What we'll do is grab the URL from a search for those buttons, then reverse engineer the code needed to make their search box work and create an HTML code snippet that'll offer the same functionality. Ready?

First off, go to search.twitter.com and search for "Avatar" as a test. You'll end up with a Web page address (URL) like this:

http://search.twitter.com/search?q=Avatar

That's really all you need to create a rudimentary button: just use a graphic or text link and have that as the link. For example:

  Avatar buzz on Twitter

Easy, eh? The source to that:

<a href="http://search.twitter.com/search?q=Avatar">Avatar buzz on Twitter</a>

Without a detailed explanation, I'll say that any time you see a URL of this type, you can also unwrap it and make it into a simple HTML form too:

<form method="get" action="http://search.twitter.com/search">
<input type="hidden" name="q" value="Avatar" />
<input type="submit" value="Avatar buzz on Twitter" /></form>

When we actually include this code, we get this:
 

Cool, yes?

Now, let's turn that into a search box. It's quite easy, actually, and the code looks almost identical:

<form method="get" action="http://search.twitter.com/search">
<input type="text" name="q" />
<input type="submit" value="search Twitter" /></form>

Well, let's add a prompt to it so you know what you're typing in and move things around just a bit:

<form method="get" action="http://search.twitter.com/search">
Search Twitter for: <input type="text" name="q" />
<input type="submit" value="go!" /></form>

Let's see how that looks:

Search Twitter for:

Nice, yes? From here you can tweak and fiddle to your heart's content, but between the different ways I show to unwrap the search.twitter.com URLs you should be able to set up just what you want on your page!









Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
Comments
Rather amazingly, there are no comments on this article yet.

I have something to say, now that you mention it, but ...
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you for all your efforts on this Web site by buying you a cup of coffee!

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Recent Entries


Search
I Need Help!
Need Help? Ask Dave Taylor!


© 2002 - 2012 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.