Twitter from command line
+
Par Remi le dimanche 26 juin 2011, 11:40 - Développement - Lien permanent
Some time ago, I wrote a small script to Twitter from command line. As the basic authentication have been deprecated, I decide to write a new version.
As always, I wrote it in PHP with the pecl/Oauth extension, available in the fedora repository (and in remi for old versions or Enterprise linux).
You can download it from https://github.com/remicollet/twit.
A very useful example: Using pecl/oauth to post to Twitter
Installation
$ su -c "yum install php-pecl-oauth"
$ wget https://raw.github.com/remicollet/twit/master/twit.php -O ~/bin/twit
$ chmod +x ~/bin/twit
Configuration
To start, you must register a consumer application on https://dev.twitter.com/apps/new. This operation will allow you to get a couple of Consumer key and Consumer secret.
Then, you need to register this codes in the application configuration:
$ twit register xxxxxxx yyyyyyyyyyyyyyyyyyy
twit version 0.1
Please visit https://twitter.com/oauth/authorize?oauth_token=zzzzzz
Then run again with 'access' option
Browsing to the displayed URL will allow the application to use your account.
Check the access:
$ twit access
twit version 0.1
Access granted !
This must be done only once, then the credentials will be recorded in the configuration file ~/.config/phptwit/account.
Utilisation
Without option, the command display the current status :
$ twit
twit version 0.1
Name: Remi Collet
Last: twit version 0.1 released, see https://github.com/remicollet/twit
Date: Sun Jun 26 08:54:02 +0000 2011
With a message, it updates the status :
$ twit 'From blog : http://blog.famillecollet.com/post/2011/06/26/Twitter-en-ligne-de-commande'
twit version 0.1
Tweet sent for RemiCollet !
Conclusion
Quite simple ?
It you want to follow me, my twitter.
Commentaires
'yum install bti' works well too
@Leif : yes, there are already a lot of other solutions, but I want to implement an oauth client in PHP. This is mainly an exercise ;)
Works with php-pecl-oauth 1.1.0 or 1.2.2 (versions 1.2 and 1.2.1 are broken).