Project Description

This project required the use of a 3rd party java library called twitter4j. It has several classes that makes using the twitter bot easier. The twitter account @sphinxibot was created to send out the programs tweets. An API key is necessary for this project because it gives the program permission to tweet from the account. Once the API key is obtained, it must be entered either in a separate file, which will later be referenced in the code, or directly in the code. This is the most pivotal and the most necessary step of the program.

To build the program, grab the four API keys from twitter. Then enter them in the template that twitter4j provides on its site (replace the stars with the actual keys). Put that information either in main or another method which will be called from main. To send a tweet, create a variable of type StatusUpdate. After the variable has been created, use the imported classes from the twitter4j library. Create a new StatusUpdate that takes in a string parameter. This parameter is the actual tweet itself. It can be passed either in a string variable or directly passed as a string. The option of attaching an image is also there. It can be either a GIF or a regular image. There are different ways to upload an image and it depends on the location of the image. If the image is on the local computer, create a new variable of type file, then pass through the location of the image as a parameter. Call the .setMedia class and pass the name of the file variable. To upload an image that exists online, use the .setMedia class and pass through a string that describes the image followed by a comma. Then provide the location of the image. When all the steps above have been completed, create a new variable of type Status. Inside this variable, call .updateStatus. The parameter that is used is the name of the variable created earlier under the UpdateStatus variable. If everything has been done correctly, the tweet should now be on twitter. The twitter4j library has several functionalities outside of just tweeting. It can send direct messages, reply to tweets, search for tweet, and do much more.

If at any point you get stuck, there are several resources you can look to. The book Build your own Application to access Twitter using Java and NetBeans: Part 1 is a great resource to turn to. When used in conjunction with the twitter4j documentation page, it can be a powerful tool. It provides step-by-step directions on how to import and setup twitter4j. It also shows you how to build the GUI for your twitter bot. The Java Code Geeks website is also another resource that might be better for this class as it utilizes Eclipse.

Visit@sphinxibot on twitter to see some of the tweets that the program sent. The hardest part about building this program is the authentication process. One of the keys that I got from the twitter API had a dash in it. I thought that it was there because the key continued on the next line.It turns out that it was not a newline key but it was actually part of the authentication keys. Once I fixed this, the authentication process began working and my program was able to send out tweets. Now that my program is able to send tweets, I made it interactive. I added am input scanner to make tweeting easier as well as gave you options.

I learned many things from this project such as how to import a custom library. Eclipse makes using this library easy by providing suggestions when I type. I spent three days trying to figure out why my program was not authentication properly. I had looked over my keys several times and it did not make sense to me. I went to a tutor and he pointed out what I was doing wrong. If I had to do it all over again, I would ask questions when I needed help instead of trying to figure out what was wrong. This project allowed me to do something that we did not learn in class and it was a great learning experience.