If everything is correct, you should be able to see a response saying "Authentication Successful". verify_credentials ( ) print ( "Authentication Successful" ) except : print ( "Authentication Error" ) set_access_token ( "ACCESS_TOKEN", "ACCESS_SECRET" )Īpi. OAuthHandler ( "CONSUMER_KEY", "CONSUMER_SECRET" )Īuth. You can even test the credentials to check if everything is working as expected using the following code snippet: import tweepyĪuth = tweepy. py and store these four keys in the key-value format as shown below: access_token = "XXXXXXX" Inside your project folder, create a new file called credentials. Here you'll find the "Keys and Tokens" tab clicking this will take you to another page where you can generate the credentials.Īfter generating the credentials, save them to your local machine to later use in your code. To create your authentication credentials, firstly, go to your Twitter apps section. Step 3: Create the Authentication Credentials Name of app: Finally, enter the name of your app.Description: The purpose of your project or how users will use your app (such as this app is used to automatically respond to tweets).Category: Select the category to which your project belongs.Project name: a name to identify your project (such as Reply-To-Mention-Bot).You need to provide the following information about your project: An app can be defined as any tool that uses the Twitter API. You have to do this process because Twitter permits authentication credentials only for apps. Once your Twitter developer account access gets approved, create a project on the Twitter developer portal dashboard. You'll receive the confirmation back within a week. Once you submit your application, you'll land on this screen : Try to be as specific as possible about your intended use for faster and better chances of getting approval. So, you have to specify the use case for your application. Twitter will ask for some information about how you're planning to use the developer account. Go to the Twitter developer platform to apply for a developer account. You need to follow the steps below to create your credentials once you have signed up to Twitter: Step 1: Apply for a Twitter Developer Account That's why you need to create those required credentials to be able to use the API. Twitter API Authentication CredentialsĪny request that is accessing the official Twitter API requires OAuth for authenticating. Rest all other libraries that you'll see in this project are part of Python's standard library, so you do not need to install them. Flask - To create a web app for deploying your application on Elastic Beanstalk.APScheduler - To schedule your job periodically.Requests - To make HTTP requests to the random quote generator API.Pillow - To create an image and to add texts over it.Installed these external Python libraries on your local environment Python 3Īt the time of writing this article, the latest version is Python 3.9, but it is always recommended to choose a version that is one point revision behind the latest one so that you do not face any compatibility issues with third-party modules.įor this tutorial, you can go with Python 3.8. To enable your bot to interact with Twitter, you first have to sign up to a Twitter developer account and create an application for which Twitter will grant you access (There is a detailed explanation of this step in the next section). You are going to deploy the final application to AWS Elastic Beanstalk so make sure you are signed up on AWS. To follow along with this tutorial, make sure you have: An AWS account This text will be a quote that you will fetch from a third-party API. The reply will be in the form of an image that you will generate and put some text over it. You will be creating a Reply to mentions bot, which will send a reply to everyone's tweet who has mentioned it with a specific keyword. In this article, you'll learn how to make your own Twitter bot in Python using Tweepy, a Python library for accessing the official Twitter API. Source code of this application is available in this GitHub repository Introduction The reply will be in the form of an image with a quote written on it. The bot will reply to every tweet in which it got mentioned with a specific keyword. TL DR: This blog post is aimed to demonstrate how to make a custom Twitter bot in Python using the official Twitter API.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |