forked from pablobarbera/social-media-workshop
/
05-instagram-data.r
78 lines (55 loc) · 2.3 KB
/
05-instagram-data.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
################################################################
## Workshop: Collecting and Analyzing Social Media Data with R
## February 2nd, 2015
## Script 5: Collecting Instagram data
## Author: Pablo Barbera, NYU, @p_barbera
################################################################
setwd("~/Dropbox/git/social-media-workshop")
# Installing the package to work with Instagram data
library(devtools)
install_github("pablobarbera/instaR/instaR")
## Loading the package
library(instaR)
## Creating an OAuth token
instagram_app_id = "XXXXXXXXXXXX"
instagram_app_secret = "XXXXXXXXXXXX"
token <- instaOAuth(app_id=instagram_app_id,
app_secret=instagram_app_secret)
## for instructions on how to create yours
?instaOAuth
## save oauth token
save(token, file="backup/instagram-token.Rdata")
## Loading backup token for presentation
load("backup/instagram-token.Rdata")
############################################
### DOWNLOADING PICTURES USING A HASHTAG ###
############################################
euromaidan <- searchInstagram("euromaidan", token,
n=100, folder="euromaidan")
# descriptive statistics
table(euromaidan$filter) ## filter used in pictures
table(euromaidan$type) ## picture or video
table(!is.na(euromaidan$longitude)) ## how many are geolocated
# finding most popular pictures
euromaidan[which.max(euromaidan$likes_count),]
euromaidan[which.max(euromaidan$comments_count),]
######################################################
### SEARCH FOR PICTURES FROM A GIVEN LOCATION ###
######################################################
# pictures around the Georgetown area
gtown <- searchInstagram(lat=38.907609, lng=-77.072258, distance=500,
token=token, n=100, folder="gtown")
getCommonHashtags(madrid$caption)
######################################################
### DOWNLOAD PICTURES FROM A GIVEN USER ###
######################################################
wh <- getUserMedia("whitehouse", token, n=200)
# finding most popular pictures
wh[which.max(wh$likes_count),]
wh[which.max(wh$comments_count),]
######################################################
### COUNTING PICTURES MENTIONING A HASHTAG ###
######################################################
getTagCount("euromaidan", token)
getTagCount("occupygezi", token)
getTagCount("selfie", token)