Social Media Analysis using twitteR
Mohd Shadab AlamLead Assistant Manager,Inductis
What will be covered?
• Introduction to twitter APIs
• How to use twitter APIs in R
• Capturing twitter data
• Google map API
• Tweets Distribution
• Sentiment analysis using twitter data
• Followers accession diagram
Introduction to twitter APIs
• API stands for application interface“a set of functions and procedures that allow the
creation of applications which access the features or data of an operating system, application, or other service”
• Two of the most commonly used APIs are:
(a) Stream API
(b) REST API
GENERAL INTRODUCTION
Introduction to twitter APIsTWO APIs: DEFINITION
(a) Stream APITo listen to the live tweets of a user, or
listen to tweets having a particular keyword we use Stream API
(b) REST APIIf we want to retrieve archival data then we
use REST API
Introduction to twitter APIsAPI input/output structure
INPUT OUTPUT
User name tweet
Key word Time
Date range Lat long (geo coding)
Lat long range followers
Language retweets
and so on… and so on..
How to use twitter API in RAUTHENTICATION
We need to log into the twitter developer account to set up an authentication channel
dev.twitter.com
Secure authentication key and password are needed before we
can start using the APIs
How to use twitter API in RAUTHENTICATION
How to use twitter API in RAUTHENTICATION
NOTE: Do not forget to register the mobile number
How to use twitter API in RREGISTERATION PROCESS
Required Libraries
install_github("twitteR",username="geoffjentry")
require(twitteR)
setup_twitter_oauth(“f5GhnjWoR17clmd85PMQfjhHO", "QUZlAyj9w9O50TbyYdlNBkV7zILLs4zjhhQFJ2sbBIxhp4Alm2")
Capturing twitter dataAPI CALL
Sample API calls:
userTimeline('MaxLifeIns', n=3200)
user$getFollowers()
t(sapply(getUser('MaxLifeIns')$getFollowers(), function(x) c(x$name, x$location, x$statusesCount)))
Capturing twitter dataHOW DATA LOOKS LIKE
C:\Users\shadab\Desktop\twitter\followers
Google map APIAPI CALL
Sample API calls:
require(ggmap)
map <- get_map(location = 'India', zoom = 4)
points <- data.frame(x = as.numeric(loci$lon), y = as.numeric(loci$lat))
ggmap(map) + geom_point(data = points, aes(x = x, y = y), size = 3, alpha = 1/3, color = "darkblue")
Tweets distributionMAP
Sentiment analysisWORD CLOUD
Positive Negative
win poor
appreciable worst
performer decrease
increase loose
nice not
and so on… and so on..
Corpus is created and word is replaced with the stem word like running is replaced with “run” etc. Frequency of positive and negative words are counted to mark a sentence as positive or negative.
Followers accession diagramThe DIAGRAM
THOUGHTS!QUESTIONS?
THANK YOU!!!THANK YOU SLIDE!!!