Charlie Harvey - tweet from a terminal with cURL

This is a neat trick. A friend was looking for a convenient way to tweet (or send to statusnet) from Bash, this is a fairly straightforward way to do that.

There are a couple of bits you need before we play with the script. You’ll need cURL installed, many Unices do this by default, but an apt-get install curl will probably work. You’ll need oauth_sign to allow you to sign in to the API. Finally you need to get an access token set up in the twitter API bit.

You can get your API details by logging in to the Twitter dev bit. Go to my applications (which is in the dropdown at the top right that has your profile pic on it). Create a new application and create your access token. You have to make it read/write rather than the default of read only.

Next grab — I put it in a directory. You’ll need to paste in the oauth details you created in the last paragraph in the appropriate places.$ cd bashtweet $ wget

Finally you have to get and compile oauth_sign.$ pwd /home/charlie/bashtweet $ wget --2013-05-01 18:28:20-- Resolving Connecting to||:80... connected. HTTP request sent, awaiting response... 200 OK Length: 8086 (7.9K) [application/x-tar] Saving to: `oauth_sign_09jan2012.tar.gz' 100%[==================================================================================================================================================================================================>] 8,086 8.14K/s in 1.0s 2013-05-01 18:28:21 (8.14 KB/s) - `oauth_sign_09jan2012.tar.gz' saved [8086/8086] $ tar xvzf oauth_sign_09jan2012.tar.gz oauth_sign/ oauth_sign/Makefile oauth_sign/oauth_sign.c oauth_sign/oauth_sign.1 oauth_sign/liboauthsign.c oauth_sign/README oauth_sign/liboauthsign.h $ cd oauth_sign/ $ make gcc -c -Wall -O liboauthsign.c liboauthsign.c: In function ‘oauth_sign’: liboauthsign.c:123: warning: implicit declaration of function ‘getpid’ liboauthsign.c:305: warning: pointer targets in passing argument 4 of ‘HMAC’ differ in signedness /usr/include/openssl/hmac.h:99: note: expected ‘const unsigned char *’ but argument is of type ‘char *’ rm -f liboauthsign.a ar rc liboauthsign.a liboauthsign.o ranlib liboauthsign.a gcc -Wall -O oauth_sign.c -L. -loauthsign -lcrypto -o oauth_sign $

Assuming that everything went to plan you should now be able to tweet from your terminal!$ ./ Beautiful Mayday. Time for a beer {"id_str":"329648285210005504","geo":null,"retweet_count":0,"user": [Lots more JSON removed] "truncated":false}