Very Simple Java Twitter Bot (Twitter4J)
Below is code for the start of a Twitter bot I am going to build in Java. It’s the most basic way of getting Oauth working (with any account, not just your developer account) and it shows your timeline and can update your status - that’s it for now. The neat thing is it uses Java’s awesome serialisation, so you only should have to authorise your twitter account once!
What you will need:
- Twitter4j Libraries
- Oauth Consumer and Secret Key off twitter
- That is it!
What the code does:
Once only:
- Gives the user an url to visit
- User enters a PIN provided by Twitter back in to the program
- The program gets the proper keys for the account from Twittter and saves them as a file
Everytime the program is restarted it reloads in account details (if the user gave permissions in steps above - it is not redone)
User is provided with a Menu and either can update status or show timeline
I started off withthis code example, so much props to Twitter4J team for a great library!