2. 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
3. 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
4. Introduction to twitter APIs
TWO APIs: DEFINITION
(a) Stream API
To listen to the live tweets of a user, or
listen to tweets having a particular keyword
we use Stream API
(b) REST API
If we want to retrieve archival data then we
use REST API
5. Introduction to twitter APIs
API 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..
6. How to use twitter API in R
AUTHENTICATION
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
8. How to use twitter API in R
AUTHENTICATION
NOTE: Do not forget to register the mobile number
9. How to use twitter API in R
REGISTERATION PROCESS
Required Libraries
install_github("twitteR",username="geo
ffjentry")
require(twitteR)
setup_twitter_oauth(“f5GhnjWoR17clm
d85PMQfjhHO",
"QUZlAyj9w9O50TbyYdlNBkV7zILLs4
zjhhQFJ2sbBIxhp4Alm2")
10. Capturing twitter data
API CALL
Sample API calls:
userTimeline('MaxLifeIns', n=3200)
user$getFollowers()
t(sapply(getUser('MaxLifeIns')
$getFollowers(), function(x) c(x$name,
x$location, x$statusesCount)))
14. Sentiment analysis
WORD 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.