Can’t believe it? Launch Rebol’s Console, and copy and paste this:


do http://reboltutorial.com/source/rebol-twitter.r

You can now tweet in one line by typing:


tweet "Hello World!"

Nevertheless do not forget the quote (you can also write a multiple-lines message using braces {}).

The first time it will ask your login and password:
rebtweetdemo

The second and next time, you don’t need to re-enter your login and password:

rebtweetdemo2

You can switch to another account with the tweetaccount command like this:


tweetaccount "reboltutorial" "thisisnotmytruepassword!" "So you cannot try this for real !"

This is the code behind the tweet and tweetaccount functions:



Rebol [
    Title: "Rebol Twitter"
    Author-Url: http://reboltutorial.com/blog/rebol-twitter-update/
    Script-Url:  http://reboltutorial.com/source/rebol-twitter.r
    Date:  23-Aug-2009
    Purpose: {
            Tweet from Rebol - Multiple Accounts support
    }
]

;it uses this library to do http post with basic authentication as requested by the tweeter API
do http://reboltutorial.com/source/http-tools.r

tweetaccount: func[user password message][

    tweetuser: user
    tweetpassword: password

    http-tools-data/username: user
    http-tools-data/password: password
    message-block: copy []
    append message-block "status"
    append message-block message
    http-tools/post http://twitter.com/statuses/update.json message-block
]

tweet: func [message][
    if not (value? 'tweetuser) [
        tweetuser: ask "user: "
        tweetpassword: ask "password: "
    ]
    tweetaccount tweetuser tweetpassword message
]

rebol-twitter

3 people like this post.
Bookmark and Share