There was a time when knowledge and views can only be spread via printing medium. At the same time, published articles were only of renowned fellows who were being followed by large population. This indirectly made common people to accept idea’s irrespective of thinking other way around. There were no healthy discussion kind of things. But majorly from the past 10 years, Internet is in the limelight and is attracting the huge crowd. Today views can spread in just a blink of an eye. Now healthy discussions and exchange of views can be easily seen via social media (like Twitter, Quora, Tumblr, etc).

Exchanging of ideas via social media is increasing day by day. Today social media is not only the platform to enjoy and chit chat with friends but it has now become a media to share the perception of the crowd towards events or topics, resulting in increase of data. Availability of huge amount of social interaction content give a lot of new opportunities. This is because human social interactions have never been recorded in such a scale in the history. We are still figuring out how to make effective use of this data. What does this mean to us? What does this mean to the users? What does this unstructured data mean to the social sites and online digital media?

So, to answer all the above questions, here comes the term “ANALYSIS” in action. Analysis simply means detailed examination of elements or the data to find some insightful observations. For example, Analysis help us to figure out the sentiments (anger, sad, happy, negative) of the person about the certain topic or action. It also helps us to predict information about some of the related phenomena in the future based on these observations.

Social Media Analytics

Analyzing the day to day events that arises from the common interests and goals is called Social Analysis. It is the place where every opinion is respected and is given equal weight. Social Media Analytics is the crucial and major part of the Social Analytics. It is the process of gathering the data from the social media (like Twitter, Tumblr, etc.) or digital media (like TOI, inshorts, newsfeed).

It is then processed in such a way that some insightful information is retrieved. Here data includes tweets, likes, post, retweets, share and many more. According to Jared Feldman, president of Mashwork, a leading social analytics firm, every second there are 4,630 tweets.

Social Media Analytics is used in businesses to analyze the sentiment of users on products. For example, when the RedMI Note4 was released the topic was popular among everyone, but as soon as the popularity and company’s name diminishes; the company launches its new product like RedMI 4A (it is the new mobile in the market, check that out it's a great phone :P).

Now, another problem is how should we fetch the data? So, we have two choices either we can scrap the data from website or use some form of application (API, to be precise). Use of Web Scraping is not a good idea as the new posts are posted in every second and it is hard for us to run the code all the time to check whether there is a new post or not. So now we need an application which do all these stuffs by itself and give us the correct results. For this, we need the API.

So, in this article I show you how to use the API and fetch the data using the Twitter’s API and in upcoming articles we will try to extract many hidden observations from unstructured and semi- structured data which are helpful in further decision making. For all our articles, we will be using Twitter as example.

What is API and how to get it?

Application programming interface(API) is a set of protocols or tools for building software applications. It specifies how software components should interact. At the same time, API’s are used for programming graphical user interface (GUI) components.

As I have stated earlier, we will be using Twitter API. It offers two APIs which are REST API and Search API. The REST API allows developers to access core Twitter data and the Search API provides methods for developers to interact with Twitter Search and trends data.

Now, I show you how to get Twitter API keys. To start with, we will need to have a Twitter account and obtain credentials (i.e. API key, API secret, Access token and Access token secret) from the Twitter developer site to access the Twitter API. (Note: Try all the steps simultaneously on your system too for the better understanding of fetching keys.)

1.) Create a Twitter user account if you do not already have one.

2.) Go to and log in with your Twitter user account. This step gives you a

Twitter dev account under the same name as your user account. Now click on “Create New App”.

Create new Twitter Apps for data analytics

3.) Fill out the form, agree to the terms, and click “Create your Twitter application”.

4.) In the next page, click on “Keys and Access Tokens” tab, and copy your “API key” and “API secret”.

Scroll down and click “Create my access token”, and copy your “Access token” and “Access token


Twitter new application setting for data analytics

Once we are done with API keys, now we will extract the tweets on certain topic. So now we will focus

on the programming part (I will suggest you use R):

Firstly, install the twitteR package using: install.packages("twitteR")


#After execution of above command, we can access the functions that are

#defined in this package.





#API that we had extracted in the above section will now be used for

#the authentication of user on Twitter. Once below command is successfully

#executed we are good to go.

setup_twitter_oauth(api_key, api_secret,

api_access_token, api_access_token_secret)

# searchTwitter method is used to get the tweets of a person or topic.

# Here n denotes number of tweets we want to get on inputed

# searchString. This method return result as a dataframe which contains

# 16 features including screenName of tweeter, date of creation,

# retweetCount in. For more info type '?searchTwitter' on console

df <- searchTwitter(searchString="#blackmoney", n=50000)


In this article, we learnt about the basics of Social Media Analytics, the importance of the data and the way to fetch Twitter data via API. I will be covering Web Scraping and its importance in the upcoming articles.


This article has been submitted by Lokesh Todwal, a pre-final year student of LNMIIT, Jaipur. He can be reached at