Twitter Notifier

Download:

Tasker Profile (raw .xml file)


Steps:

Contexts

  • Create a new profile
  • Choose the Time Context and set whatever update frequency you'd like as the repeat element (I used 10 minutes in my profile)
  • Go ahead and hit done and we'll start adding tasks

Tasks

  • This is going to get a bit hairy, but basically what we're doing is asking the twitter search API for a listing of all mentions since our last check and the creating an alert if one exists.
  • Ok, first create a variable (Variable -> Variable Set) named %TWRUSER with the value of your twitter user name.
  • Now, create a variable (Variable -> Variable Set) named %SINCEID with the value of 0. Also, add an if clause (found at the very bottom) of "If %SINCEID !Set" This basically initializes that variable but only the first time you run the program as we update it on every run.
  • Now, go to Net -> HTTP Get and add the following to the Server:port area without the surrounding quotes: "search.twitter.com/search.json?rpp=1&since_id=%SINCEID&q=to%3A%TWRUSER"
  • Let's create a stop action (Tasker -> Stop) with an if clause of "%HTTPD !Set". This is to catch an issue of the search API being down (happens more often than you'd think).
  • Now we're going to parse the response for the max id and update our variable.
  • Variable -> Variable Split: Use the %HTTPD variable, use the following for the delimiter: max_id":
  • Make sure you include that last quote and colon in the previous step in the delimiter section. That creates two new variables, %HTTPD1 and %HTTPD2. We don't care about 1, just 2 as it starts with our new SINCEID but it has a lot of extra junk at the end of it so we'll split it one more time to get rid of that.
  • Variable -> Variable Split: Use the %HTTPD2 variable, use a comma as the delimiter.
  • This may create a lot of new variables, but we only care about %HTTPD21 as this is our SINCEID
  • Variable -> Variable Set - Name: %SINCEID Value: %HTTPD21
  • Now we've stored the new SINCEID, lets go back and check the response for an actual new mention.
  • I like to use Alert -> Notify Sound - Text: New Mention with an if clause of %HTTPD !~ (doesn't match) {"results":[]*
  • We use this if clause because a response with no recent mentions looks like:
{"results":[],
"max_id":20732317546848256,
"since_id":20732317546848256,
"refresh_url":"?since_id=20732317546848256&q=to%3Ajtsmith2",
"results_per_page":1,
"page":1,
"completed_in":0.024473,
"since_id_str":"20732317546848256",
"max_id_str":"20732317546848256",
"query":"to%3Ajtsmith2"}

The big thing to notice here is that the result set is empty. So the above if statement just notifies you if that result set is NOT empty.

Drawbacks and Todos

  • The biggest drawback of this method of using the search API is that you're not going to get notified of any mentions coming from a user with protected tweets. If the search engine on twitter doesn't return it publicly, then this won't see it either.
  • I would like to extend this by being notified of the actual tweets that were sent to me. It won't be that hard to do as the full response with actual returned tweets gives you the number of returned tweets so a counter loop would be easy to make and the just iterate through creating a notification with username and text from each tweet.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License