Introduction: Tic Tac Toe Twitter Bot for PCDuino
-Monitor, mouse and keyboard (or any other way to access your PCDuino)
Step 1: Create a Twitter Account
FIrst we need to create a Twitter account for our bot. Go to https://twitter.com and sign up. Also add a phone number to the account, which is required in order to get access to the Twitter API. When you're done, go to https://apps.twitter.com and click on 'Create New App'. You will be taken to a screen that asks you to fill out some information about the app. When you've done that, click on 'Create your Twitter application'. On the next page, go to the 'Permissions' tab, select 'Read, Write and Access direct messages' and then click on 'Update Settings'. Then go to the 'Keys and Access Tokens' tab. At the top of the page, you will find the values of your consumer key and your consumer secret. At the bottom of the page, click on 'Create my access token' and you'll see your access token and your access token secret. Write these four values down, because we will need them later on.
Step 2: Set Up the Board
For the playing board, we will use 9 LEDs, connected to the GPIO pins of the PCDuino. Set up the board like in the image above.
Step 3: Install Java
For our bot we will be using a Java program, so before we can run it we need to install the Java Runtime Environment on the PCDuino. To do this, open the terminal (Ctrl+alt+T), type in 'sudo apt-get install openjdk-7-jre' and press enter. When asked 'Do you want to continue?', press enter. Then wait for the installation to finish.
Step 4: Download and Run the Bot
Download the file tictactoe.jar (see below) on your PCDuino. Before you run it, open the file with an archive manager (right click on the file -> Open With). Inside the archive file, there is a file called twitter4j.properties. Open it with a text editor. On the first line you will see the text 'oauth.consumerKey='. Type your consumer key (which you wrote down at step 1) after the equals sign. Do the same for your consumer secret, your access token and your access token secret. Then save the file.
Now you're all set. To run the bot, type 'java -jar tictactoe.jar' from the directory where you stored the file, and it should execute. You should see text appearing in the terminal screen, telling you the program is receiving data from Twitter. If you get an error, check your twitter4j.properties file and make sure you filled out everything correctly.
So how does the bot work? When two random Twitter users send a direct message containing the text 'play' to your Twitter account, they will be put into a game together. A player can then make a move by sending you a direct message that contains a number which corresponds to their move. The two players will alternate turns until the game ends. The bot will start a new game when two new players have joined.
We have a be nice policy.
Please be positive and constructive.