Created
April 7, 2015 09:39
-
-
Save josefslerka/870f55cd02daeb05b1b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(Matrix) | |
library(igraph) | |
library(plyr) | |
library(Rfacebook) | |
library(rjson) | |
library(Hmisc) | |
########################################################### | |
# I. stazeni postu a komentaru ze stranky a jejch ulozeni # | |
########################################################### | |
########################################### | |
# 1. stazeni postu z analyzovane stranky # | |
########################################### | |
# stranka, ktera bud analyzovan | |
PagetoAnalyze <- "87351004630" | |
# pocet postu k analyzovani, ktera bud analyzovan | |
NumberOfPosts <- 300 | |
fileName <- paste0(PagetoAnalyze, ".csv", collapse="") | |
# sem je treba dat token z https://developers.facebook.com/tools/explorer/ | |
token <- "CAACEdEose0cBAAPjWnfodvK225KCJPFIKMvakBZBaZCIIwtoGwviGR22gogIt8xIkt0ubZCLKsdQgxNmrAswFxPLuy6YkhqtEEmtzb9JJbZBdIpJtO73F7o2m5ZAhdK2cOiNRJf4e8vkpJjWuerFMb87ZB5qiZC7nZBkT6yqTqEYGoHgbRRE43xlIPLRMimCgunHDWjrySYZAWYNDZBZCTSLEJZAcGGJ1vkEKhcZD" | |
page <- getPage(PagetoAnalyze, token, n = NumberOfPosts) | |
# ulozi soubor s posty strank | |
fileName <- paste0(PagetoAnalyze, "_posts.csv", collapse="") | |
write.csv(page, fileName) | |
########################################################### | |
# 2. stazeni seznamu komenutujicich jednotlive posty # | |
# - error to pise pokud jde o post, # | |
# ktery nevaraci komentujici ani nerekne nula, # | |
# vetsinou kometare samotne stranky # | |
########################################################### | |
toAnalyze <- page$id | |
dfComments <- data.frame(from_id=character(),from_name=character(), message=character(), created_time=character(), likes_count=character(), id=character(),post_id=character()) | |
for(v in toAnalyze) { | |
cat(v) | |
cat("\n") | |
post <- getPost(v, token, n = 3000, likes = FALSE, comments = TRUE) | |
requests <- tryCatch({ | |
dfPost <- as.data.frame(post$comments) | |
dfPost$post_id <- v | |
dfComments <- rbind(dfPost,dfComments) | |
}, error = function(errorCondition) { | |
cat("error") | |
cat("\n") | |
}) | |
} | |
# ulozi seznam komentujicich a jejich komentare | |
fileName <- paste0(PagetoAnalyze, "_comments.csv", collapse="") | |
write.csv(dfComments, fileName) | |
#### likers | |
toAnalyze <- page$id | |
dfLikes <- data.frame(from_id=character(),from_name=character(), message=character(), created_time=character(), likes_count=character(), id=character(),post_id=character()) | |
for(v in toAnalyze) { | |
cat(v) | |
cat("\n") | |
requests <- tryCatch({ | |
post <- getPost(v, token, n = 3000, likes = TRUE, comments = FALSE) | |
dfPost <- as.data.frame(post$likes) | |
dfPost$post_id <- v | |
dfLikes <- rbind(dfPost,dfLikes) | |
}, error = function(errorCondition) { | |
cat("error") | |
cat("\n") | |
}) | |
} | |
# ulozi seznam lajkujicich a posty, ktere lajkovali | |
fileName <- paste0(PagetoAnalyze, "_likes.csv", collapse="") | |
write.csv(dfLikes, fileName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment