loading

I live in a place where data plans are still extremely limited and overpriced. Over the years I've learned to make do with a basic phone plan which I mainly use to send text messages with. But there are times when I'm lost on the road and have no choice but to find a local coffee shop with WiFi just so I can Google an address or number. That is, until I had this idea – what if I could simply Google search with a text message?

The implementation is simple. All we need is one Twitter account linked to our mobile phone so that we can tweet out a search query through SMS, and another Twitter account, controlled by a server application, that listens to the SMS tweets from our phone and tweets out the search results. As long as the Twitter account linked to our phone accepts SMS notifications from the Twitter account controlled by the server, then all search results will be returned to our phone as an SMS.

www.evankale.blogspot.ca

Step 1: Requisites

  1. Basic programming knowledge is required. There will be example source code included for the server application - you will need to know how to compile Java or can translate it to another language of your choice.
  2. Your mobile carrier will also need to have Twitter SMS support.

Step 2: Obtaining API Keys

We will start by obtaining all the necessary development keys so that our server app can perform a Google search and push the results to Twitter. We'll need to make use of the Twitter API and Google's Custom Search Engine API.

For Twitter, we will need 4 keys:

  1. OAuth Consumer Key
  2. OAuth Consumer Secret
  3. OAuth Access Token
  4. OAuth Token Secret

For Google's custom search (CSE), we will need 2 keys:

  1. Google developer API key
  2. Google CSE engine ID

Step 3: Create a Twitter Account for the Server

We'll first head over to www.twitter.com to sign up for a new account that will be used to push search results.

Step 4: Verify Mobile Number

In the new account, go to settings, head to the mobile section, and link a mobile phone number to the account. We will then need to verify the number with a PIN that is SMS'd to the phone number.

Twitter developer accounts require a linked phone number to create developer keys, once we obtain those, we will be transferring our phone number to another account.

Step 5: Create a Twitter App

Head over to http://apps.twitter.com to create a new Twitter application.

Step 6: Obtain Twitter Keys

In the app settings, set the access level to "Read, Write, and access direct messages". Regenerate both consumer keys and access tokens, and take note of them.

These keys should be kept privately.

Step 7: Create Twitter Account for Search Querys

Go back to Twitter settings and unlink our mobile phone number from the server account. We'll then create a new Twitter account and link our mobile number to this new account.

For the mobile settings of this new Twitter account, turn on "Tweets from people you've enabled for mobile notifications", and turn off the rest.

Step 8: Follow the Server Account

Using the new account, we will search for the handle of the server account, follow it, then turn on mobile notifications from it. Now we're done with Twitter!

Step 9: Creating a Google Account

Moving on to obtaining our Google keys - head over to https://accounts.google.com to create a Google account if you don't already have one.

Step 10: Create a New Google Project

While signed in to our Google account, go to https://console.developers.google.com/project. We'll create a new project, give it a name, and leave the project ID as is (can be changed but has naming restrictions).

Step 11: Enable Custom Search API

In the project details, navigate to "APIs & auth", then "APIs". Search for the term "search", then click on "Custom search API" and enable it.

Step 12: Create API Key

Under the "credentials" subcategory, click "Create a new key", then create a new server key. Enter the IP address of the location of where our server will run. In my case, this would be my home IP address. We can check our public IP address from https://www.whatismyip.com/.

Afterwards, make note of our API key that has been generated.

Step 13: Create a Custom Search Engine

Head over to https://cse.google.com/cse to create a custom search engine.

Step 14: Custom Search Engine Settings

In this example, we will limit our search results to Yelp results. More sites to search (or even the entire web) can be added, but narrowing down our search to a single site can help us pinpoint the exact results we are looking for.

Step 15: Obtain Search Engine ID

In our custom search engine setup, click on "Search engine ID", and make note of it. Now we've obtained all the necessary keys and IDs!

Step 16: Building the Server Application

(Sample server application source code written in Java is provided in the next step)

There are two parts to building the server application:

  • Twitter management - receives tweets from the account linked to mobile phone (using the Twitter streaming API), and tweets out the Google search results (using the Twitter update API).
    • I used Twitter4J (a Java library that encapsulates the Twitter API), to handle both streaming and update APIs. Various other libraries are available in different languages.
  • Google search management - performs a Google search with the search query tweeted out from the account linked to the mobile phone (using Google Custom Search API).
    • A simple HTTP GET query in the form of:

    https://www.googleapis.com/customsearch/v1?key=insert_your_API_key_here&cx=insert_your_search_engine_ID_here&q=insert_a_search_query_here

    will return a JSON object containing the search results of the input query. I used JSON in Java to parse this result and tweet out the appropriate information.

    Step 17: Server Source Code Sample

    Head over to https://github.com/evankale/TwitterPoster to download the sample server source code (hit "Download ZIP" if you don't have Git set up). You will need to be set up to compile Java or be able to translate this source into another language.

    You will need to replace the place holder Strings in TwitterManager.java with the appropriate Twitter keys and account ID (one linked to mobile phone), and the place holder Strings in GoogleManager.java with the Google CSE keys.

    This server sample app is designed to search two sites - Wikipedia and Yelp.

    To perform a Wikipedia search - send an SMS to twitter shortcode (ie, tweet) a search query in the form: "wiki [random string] [max number of search results returned] [search string]"

    To perform a Yelp search - send an SMS to twitter shortcode (ie, tweet) a search query in the form: "yelp [random string] [max number of search results returned] [search string]"

    A list of Twitter shortcodes can be found here: Twitter shortcodes

    Limitations:

    • Every tweet has a maximum character limit of 140. All tweets above 140 characters are truncated. All spaces are removed in the Wikipedia search to save characters.
    • Twitter's API limits a user to make 15 request every 15 minutes (ie, post 15 search results every 15 minutes)
    • The exact same tweet cannot be tweeted more than once. This can bypassed by adding a random string in the tweet.

    Step 18: Where to Put the Server?

    Many of us probably don't want to leave a server computer running in our homes 24/7 just to provide a search service for ourselves.

    So I chose to run my server on a low powered Android device that I no longer use (an old Samsung Galaxy Q phone that runs Android 2.2). An Android project of the sample server app can be found here: https://github.com/evankale/TwitterPosterAndroid

    Another idea is to run the server app on your home router if it is capable of running homebrew programs (ie, a router flashed with DD-WRT firmware).

    Virtual private server hosting is also another way to go - although the monthly cost of a subscription is not worthwhile for running this single service.

    Step 19: Conclusion

    That's it! Happy Tweeting!

    If you liked this Instructable, then perhaps you'll like some of my other projects! You can check them out at Blogspot, or visit my YouTube Channel.

    About This Instructable

    1,677views

    41favorites

    License:

    Bio: www.youtube.com/EvanKale91 === www.facebook.com/EvanKale91 === www.twitter.com/EvanKale91 === www.evankale.blogspot.ca
    More by EvanKale:Pokemon Card Door Guitar Cajon Mod (Internal Snare) Ratchet Knob (Unidirectional mechanism) 
    Add instructable to: