![]() The twitter package is a third party module that makes interacting with the Twitter API easier for Node.js users. npm install twitter dotenv bluebird -save API_KEY=XXXXXXXXXXXXXXXX SECRET_KEY=XXXXXXXXXXXXXXXX ACCESS_TOKEN=XXXXXXXXXXXXXXXX ACCESS_TOKEN_SECRET=XXXXXXXXXXXXXXXXįinally, let’s install some modules to our project that will help us navigate the Twitter API and store our API keys. Replace the ‘X’s which your own API keys obtained above. env file will store our API keys as global variables. The file config.js will store several helper methods that will help us interact with the API and simplify our code in bot.js. envįirst, bot.js which will store the main source code for our Twitter bot. This will generate a package.json file which keeps tracking of your project details and packages used. ![]() You will be asked to name your project and accept all the prompts before initializing your project. In order to initialize it as a Node.js project run npm init Head over to the directory where you store your projects and run the following command: mkdir twitter-bot cd twitter-bot Once you’ve done that, start by creating and entering your project folder. You can find instructions on how to do that here. You will need to install Node.js if you don’t have it already. ![]() Set up our Node.js Projectīefore we can write any code, let’s set up our Node.js project. Now to the fun part! Let’s get our hands dirty with some code. Take a deep breath…and we’re done with the set up. Click on Keys and Tokens and click Generate for the Access Token and Access Token Secret. Head over to your App’s settings page which can be accessed by clicking on your App name on the left navigation bar. We’re almost done with the set up! We just need to get a few more Access Token keys which we also need to authenticate our account. Make sure to store your API keys in a safe location since these keys will be used to authenticate our account. Once you click Create App, you will be asked to name your App before receiving your API keys. As you can see, I’ve already created an App, but I’ll show you how to create your own. Once, you’ve completed the approval process (which may take up to 24 hours), you will have access to your own personal developer portal that look something like this. The more thorough your answers, the faster the approval process. The forms are pretty standard, but make sure to provide adequate information when asked about the type of projects you expect to build with the API. The application will ask you for a bunch of details regarding your contact information, reasons for using the Twitter API, and programming experience levels. Then, you’re going to need to apply for a developer account through their website here. If you don’t want your bot to be associated with your personal account, create a new Twitter account under your bot’s name. You will need to make a Twitter account (if you don’t already have one) which will be the account that makes the posts. In order to access Twitter’s API, we need to first create a developer account. If that tweet contains some media, then our bot will reply with a video, and if it does not have any media attached, our bot will respond with a message like Oops, looks like you didn’t provide a media file!. In this tutorial, I’ll go over how to set up and build a simple Twitter bot that searches for tweets with the hashtag #FilterMe. I wanted to develop a simple real time Twitter bot that actively filters through all tweets containing a certain hashtag and replies with videos/images directly to the tweet. Twitter makes it really easy to build bots that can interact with tweets, users, and analytics tools that can scrape the platform for useful insights.
0 Comments
Leave a Reply. |