Writing an Android Twitter Client with Python

Get up and running with the Android Scripting Environment. Whip up a Twitter update app in a matter of minutes and tell everyone what sandwich you're eating from within Android!

There are many Android tutorials on the Internet and books in the bookstores showing how to write applications — I know, I’ve read many of them and have even been fortunate enough to have the opportunity to write a few myself. Up until this point, every Android application I have seen has been written in Java with a few of the more intrepid tutorials covering the topic of getting a “C” application to run on Android.

While writing applications in Java and the Android SDK is really pretty easy for a coder with an interest in learning the SDK, there is a bit of a learning curve in getting the tools setup, navigating the SDK and getting your application to run happily on the device. If you are looking to write an application for the Android Market, using the SDK is the way to go.

But what if you are interested in just hacking around a little on the device itself? What if you’re looking for a mobile Internet device that you can program anywhere — even while you are waiting patiently at the doctor’s office?

With the Android Scripting Environment, you can do just that! If you are familiar (or willing to learn) Python, Lua, or BeanShell, you can write applications directly on your Android device — no laptops, no compilers, no kidding. Follow along as we learn about the Android Scripting Environment and create a script in Python to submit entries to your Twitter account.

Android Scripting Environment

The Android Scripting Environment (ASE) installs to your Android device just like any other Android application. You can download the ASE installation file from its project page on googlecode.com. I have the alpha 0.7 version of ASE installed on my development phone.

You can use ASE to write applications much as you would in any Linux environment. Interact with the user, perform calculations, connect to the Internet. You can even access a subset of the Android SDK functionality from the scripting environment such as reading Android’s sensors and launch other applications. This flexibility allows an experienced developer (or script writer) to customize the Android environment without having to go the SDK development route. Scripts can be installed as a Service to be available at all times or be even triggered by the Locales plugin.

Once the ASE application is installed and launched on your Android phone, you will see the “Script Manager” where all activity is initiated.

Script Manager
Script Manager

The ASE installs with a handful of sample scripts which demonstrate basic scripting functionality. Clicking on any of the scripts will start the script in a new terminal window using the appropriate script interpreter engine. The file extension determines which interpreter is launched.

For example, a script with a “.bsh” extension is processed via the BeanShell interpreter. To create a new script, select the menu button and choose “Add”. If you want to enter script commands directly into the interpreter, choose the “Terminal” menu selection. You can choose from each of the supported and installed script interpreters. To edit or delete an existing script, perform a long-click (press and hold) of the selection.

Script Editing Actions
Script Editing Actions

Note that you can also create a shortcut on the home/launch window. This is helpful if you write something useful (of course you will!) and want to be able to launch it quickly. I created a shortcut to my “Twitter Status” script, which is in the script file named ts.py.

Script Editing Actions
Script Editing Actions

It is time to have a look at our script. To test this script, you will require an Android device (or emulator) with internet access. As already mentioned, you can edit scripts directly on the device through the ASE ScriptManager code window, however you may not want to type all of the code directly into your device. Good news — you can simply copy the file to your device as a starting point.

Next: Confessions of a Python Newbie

Comments on "Writing an Android Twitter Client with Python"

hello, am trying the above application but am receiving the following error
statusdata=”%(result)s “% statusmsg
TypeError: format requires a mapping

Kindly help

Regards
Boniface

Reply

Boniface, simply change the first line to:

statusdata=”%s ” % statusmsg

Reply

Thanks for any other informative website. Where else may I get that type of info written in such a perfect approach? I have a mission that I’m simply now running on, and I’ve been at the glance out for such info.

Reply

Great blog here! Also your web site a lot up fast! What host are you the use of? Can I get your affiliate link on your host? I wish my site loaded up as fast as yours lol

Reply

I am not sure the place you are getting your information, however good topic. I needs to spend a while studying much more or working out more. Thanks for excellent information I used to be on the lookout for this information for my mission.

Reply

I’m getting an error after fixing the “%s” %statusmsg line.

complains that for that line, “not all arguments converted during string formating”.

Any suggestions?

Reply

    I know I’m a bit late to offer help, but I had the same probleems as you. I fixed most of them by changing a few lines.
    droid.getInput(…..
    change it to
    droid.dialogGetInput(…
    , then
    statusdata = “%s” % statusmsg
    To
    statusdata = statusmsg.result
    Or just add .result to then end of input and change the variable to statusdata, omitting statusmsg altogether. Hope that helped even if just for my own curiosity

    Reply

Fantastic goods from you, man. I have understand your stuff previous to and you are just too magnificent.
I actually like what you have acquired here, really like what
you’re stating and the way in which you say it. You make it enjoyable and you still take care of to keep it wise. I cant wait to read far more from you. This is really a wonderful site.

Reply

Thanks for putting this out here. I am just now trying it out, but without success. Does the script still work for others that it worked for before. My concern is if twitter is enforcing https and that could be my problem.

Reply

Whoa! This blog looks exactly like my old one! It’s on a totally different topic but it has pretty much the same page layout and design. Superb choice of colors!

Take a look at my web blog :: virginia beach virginia hvac

Reply

Thank you, I have just been searching for information approximately this subject for a long time and yours is the
greatest I have found out till now. However, what about the bottom line?
Are you certain in regards to the source?

Reply

Magnificent beat ! I wish to apprentice while
you amend your website, how can i subscribe for a weblog site?
The account aided me a appropriate deal. I had been a little bit acquainted of this your broadcast provided bright transparent idea

Reply

I simply want to mention I am newbie to blogging and site-building and certainly liked your page. More than likely I’m want to bookmark your blog . You really come with good stories. Thank you for revealing your web-site.

Reply

Definitely would love to start a website like yours. Wish I had the time. My site is so amateurish compared to yours, feel free to check it out: http://tinyurl.com/o55af8p Alex :)

Reply

I just want to say I am just beginner to blogs and truly savored this blog site. Most likely I’m planning to bookmark your blog . You actually come with excellent stories. With thanks for sharing with us your blog.

Reply

I actually really like such elder scrolls online gold! Relating to these folks in black color and they are consequently nice classy each with everything! I adore that anyone can bring these products pair of alternative methods. Yes these are steep however they are really worth the bucks! I probably would entirely recommend highly him or her you can really like these people once you see these products.

Reply

I just want to tell you that I am new to blogs and certainly enjoyed you’re web blog. Very likely I’m likely to bookmark your site . You amazingly come with very good stories. Thanks for sharing your web-site.

Reply

When it arrives to figuring out all the ins and outs of a
movie sport|specifically the ones on your phone|you could
spend hundreds of hrs on finish making an attempt to defeat it this is why Sweet Crush Saga Stay Device three.eight.five was designed!

For you gamers to take advantage of all the particular feature this resource gives.
Not only you will positive aspects from all these characteristics but you will also help your self conquer every and every degree
the annoyed you for a even though. No far more waiting hrs to get lifestyle or have
a constrained quantity of boosters. Now every thing you wish has been
integrated in this tool and compatible with Facebook|Apple Units (Ipod|Ipad|Iphones) and
Android telephones also.

Reply

thank you for share!

Reply

I? not that much of a online reader to be honest butt your blogs really nice, keep it up!

I’ll go ahead and bookmark your site to come bac later.
Cheers

Reply

thank you for share!

Reply

I just want to mention I’m beginner to blogging and site-building and certainly loved this page. Likely I’m going to bookmark your website . You surely have exceptional writings. Thanks a lot for revealing your website.

Reply

Awe-inspiring Guidelines In addition to Enjoyment Truth With regards to Panthera pardus Gecko

Reply

I simply want to tell you that I am just newbie to blogging and site-building and actually enjoyed this blog site. Almost certainly I’m likely to bookmark your blog . You definitely have superb article content. Bless you for sharing your web site.

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>