Twitter will allow us to mine the data using Twitter API or Tweepy in Python for Data Science. The data from the tweets will be extract from the user. But first of all, we have to get the consumer key, consumer secret, access key and access secret from the twitter developer available easily for each user. The keys available will help API for authentication.
Steps for obtaining the keys:
- First, we should login to twitter developer section.
- Then we should go to the “Create an App”.
- Then we should fill the details of the application.
- Next, we will create our Twitter Application.
- The details of our new app will be shown along with the consumer key and consumer secret.
- For getting the access token, we should click on “Create my access token”. The page will be refreshed, and an access token will be generate.
Tweepy is one of the libraries which should be install using pip. Now we should use the OAuth Interface for authorizing our app for accessing Twitter on our behalf. So, tweepy will provide a convenient Cursor interface for iterating through different types of objects. Twitter allows us to extract a maximum of 3200 tweets.
Below is the code for implementation using explanation.
The script given above will generate all the tweets of particular users, and then it would apprehend the empty array tmp. Tweepy is there here as a tool for accessing Twitter data in a fairly easy way in Python. We can collect different types of data with focus on “tweet” objects. After collecting the data, we can use the data for different types of Analytical operations.
One such application is sentimental analysis. We can use Machine learning algorithm on the data extracted after tokenizing each word.