-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathIndividual.R
62 lines (47 loc) · 2.17 KB
/
Individual.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
# Fetch data about the selected individual
individual <- FacebookFetch(access.path=paste(individual.id),access.token=access.token )
if (length(individual$id)) {
cat ("Working with individual: ",individual$name," (",individual$id,")\n", sep="")
} else{
cat("Message: ", unlist(individual)[1], "\n")
cat("Type: ", unlist(individual)[2], "\n")
cat("Code: ", unlist(individual)[3], "\n")
stop(" Cannot continue")
}
# Fetch an individuals photos
individual.photos <- FacebookFetch(access.path=paste(individual.id,"photos", sep="/"),access.token=access.token )
# Fetch the url of the indiviiduals photos
if (!is.null(individual.photos$data)) {
individual.photos.url <- sapply( individual.photos$data, function(x){
url <- x$source
url <- gsub("https","http",url)
})
# Create the location to store the individuals photos locally
individual.photos.file <- paste("photos",individual.id,basename(individual.photos.url), sep="/")
}
# Get the individuals posts
individual.posts <- list()
i <- 0
next.path <- paste(individual.id,"posts", sep="/")
while(length(next.path)!=0) {
i<-i+1
individual.posts[[i]] <- FacebookFetch(access.path=next.path , access.token=access.token)
next.path <- sub("https://graph.facebook.com/", "", individual.posts[[i]]$paging$'next')
}
individual.posts[[i]] <- NULL
# Parse the list, extract number of likes and the corresponding text (status)
# Get the text of the message
individual.posts.messages <- unlist(sapply(individual.posts, ParsePosts, f=ParsePostMessages))
# Get the count of the likes
individual.posts.likes <- unlist(sapply(individual.posts, ParsePosts, f=ParsePostLikes))
# Get a count of the comments
individual.posts.comments <- unlist(sapply(individual.posts, ParsePosts, f=ParsePostComments))
# Get the individuals posted links
individual.links <- unlist(sapply(individual.posts, ParsePosts, f=ParsePostLinks))
# Get the number of likes for any given link
individual.links.likes <- unlist(sapply(individual.posts, ParsePosts, f=ParsePostLinkLikes))
# Display the three most popular links
cat("Displaying the three most popular links by this individual:\n")
cat(individual.links[order(individual.links.likes,decreasing=TRUE)][1:3])
rm(i)
rm(next.path)