For this new article, KoS (author of this article) has contacted San Bergmans site http://www.sbprojects.com to talk about its tutorials. And so today KoS offers with the help of San a method to send tweets from the Raspberry via a script.
Before your Raspberry Pi can send Twitter messages, also known as the Tweets, you need to create a twitter account for him http://www.twitter.com/ (If you do not want your Pi tweet on your own account). But that is not all, You must also create an account on Supertweet http://www.supertweet.net/. Supertweet will be linked to the Twitter account via the 0Auth process, This will allow you to use the Supertweet API to send tweets. This is necessary because Twitter has stopped providing its own API.
You will also need to install curl, a small tool that you can install by typing the following command :
sudo apt - get install curl
Just copy the script below and paste it in a text editor such as nano on your Raspberry Pi. After you paste the text into your editor change two variables with your information. TWIT_USER is the username of your Twitter account and TWIT_SECRET is the password of your account Supertweet. Then save the file with the name Tweet in your binary directory (NdT : /default bin). Personally I always keep my scripts in the directory /Home/pi/bin, This is my way.
And don't forget to make the file executable with the command
chmod u x tweet
NdT : Alternatively, you can change the owner of the script, What will prevent you from having to do a sudo to call it : sudo chown ft. tweet
# This script sends tweets
# Use :
# Tweet "the string to tweeter"
# Special characters will not be taken into account if you do not delimit your string with single quotes
curl u $TWIT_USER:$TWIT_SECRET-d "status = $TWEET" $TWIT_URL s > /dev/null
NdT : attention, It is possible that the address of the API changes, If the script does not work anymore, check the address on Supertweet
Once you have backed up and made the script executable , You can begin to send tweets with a command such as :
Tweet “Wow, My Raspberry Pi can send tweets through the script found on www.sbprojects.com“
Remember that the tweets are limited to 140 characters. The script will simply truncate messages larger than 140 characters. And apparently it deals web links also, as you can see in the previous example.
Room for improvements
Supetweet sends an XML file after each sent tweet, containing a wealth of information. I simply delete this XML file by sending it to /dev/null. However, you can modify the script to see what Supertweet has to tell you if you want to.
You can change the behavior of the script to reject the above tweet 140 characters instead of cut off. You choose what you prefer.
Some safety advice
Twitter will ignore the same tweet sent at too frequent intervals. Which means you won't be able to send a tweet with the same text again and again. You can easily solve this problem by adding a timestamp to your message.
Furthermore, I saw that Supertweet (or Twitter) sometimes jumps a message. Therefore, You cannot be absolutely sure that your tweet is going to happen. I have no idea why it happens, It is thus. The XML message returned by Supertweet (ignored by my script) gives no idea of why some tweets are ignored.