Python ProgrammingPython Programming

Twitter Data Mining

Twitter is a potential gold mine for data miners, let us see how to pull the data.

Twitter has a huge volume of data with a lot of significance in it. There is an approx 500 million tweets per day, and every tweet has some story to tell. Twitter allows companies to promote their products in short messages known as tweets limited to 140 characters which appear on followers. If someone has been unsatisfied with our company’s service, they might tweet angry feedback that would be counted as a negative tweet. Similarly, another user could tweet a recommendation for that company because they received a good customer service, which would be considered a positive tweet. When all of this data is collected and interpreted, it gives an enormous amount of insights to a business about their company, product, service, etc.

Twitter offers a series of APIs which provides access to retrieve Twitter data, including reading tweets, accessing user profiles, followers and so on. In order to access Twitter data, there are two preliminary steps need to follow:

Application Registration

Log in to the Twitter developer portal(https://developer.twitter.com/), all we need to do is point our browser to the Application Management page from Apps to menu and create the new app.

Twitter API client selection

Once the app is registered, under the Keys and Access Tokens tab, we can find the information we need to authenticate our application.

  • Consumer API key: Key associated with the application (Twitter, Facebook, etc.).
  • Consumer API secret key: Password used to authenticate with the authentication server (Twitter, Facebook, etc.).
  • Access token key: given to the client after successful authentication of above keys.
  • Access token secret: Password for the access key.

The Access Level of these settings defines what the application can do while interacting with Twitter on behalf of a user: read-only is the more conservative option, as the application will not be allowed to publish anything or interact with other users via direct messaging.