still have to fix JSON validation errors

This commit is contained in:
2014-11-30 03:41:23 +01:00
parent c2190c7060
commit 0be709ff08
5 changed files with 566 additions and 237 deletions
+56 -14
View File
@@ -15,16 +15,27 @@ handle <- getCurlHandle(httpheader = list(from = "max.mehl@uni.kn",
)
acc_url <- "http://www.bundestwitter.de/api/politiker"
acc_json <- readLines("politiker.txt")
acc_df <- fromJSON(acc_json)
#acc_json <- readLines("politiker.txt")
acc_df <- fromJSON(acc_url)
# --------------
url <- "https://api.twitter.com/1.1/statuses/user_timeline.json";
query <- c(screen_name="mxmehl", include_rts=1, count="200", exclude_replies="true", trim_user="true", include_entities="false");
as.character(as.numeric(result$id_str[nrow(result)]) - 1)
str_detect(result$created_at[nrow(result)], "2013$")
result <- fromJSON(correctJSON(twitter_api_call(url, query, params)))
# ---------------
# http://www.joyofdata.de/blog/twitters-rest-api-v1-1-with-r-for-linux-and-windows/
# devtools::install_github("joyofdata/RTwitterAPI")
params <- c(
api_params <- c(
"oauth_consumer_key" = "c9Ob2fWNSONMC0mA2JlNaeRke",
"oauth_nonce" = NA,
"oauth_signature_method" = "HMAC-SHA1",
@@ -33,18 +44,49 @@ params <- c(
"oauth_version" = "1.0",
"consumer_secret" = "cZ3Il2hmbLgK0Lc57mj5kUvymjVdsmZKYwKOGHR3NhCpvWgEOI",
"oauth_token_secret" = "rvfv8MgexFKTqrPNSoGrdrZVNhV4fTJb2Bgz249nbvKNg"
);
)
url <- "https://api.twitter.com/1.1/statuses/user_timeline.json";
query <- c(screen_name="mxmehl", include_rts=1, count="200", exclude_replies="true", trim_user="true", include_entities="false");
as.character(as.numeric(result$id_str[nrow(result)]) - 1)
str_detect(result$created_at[nrow(result)], "2013$")
result <- twitter_api_call(url, query, params)
result <- fromJSON(correctJSON(result))
api_url <- "https://api.twitter.com/1.1/statuses/user_timeline.json";
user <- "peteraltmaier"
max_count <- "200"
max_id <- "999999999999999999"
loop <- 1
keep <- c("created_at", "id_str", "text", "retweet_count")
rm(tweets_full, tweets_temp)
repeat {
query <- c(include_rts=1, exclude_replies="true", trim_user="true", include_entities="false",
screen_name=user,
count=max_count,
max_id=max_id);
if(exists("tweets_full")) {
current <- twitter_api_call(api_url, query, api_params)
tweets_temp <- fromJSON(correctJSON(current))
tweets_temp <- tweets_temp[keep]
tweets_full <- insertRow(tweets_full, tweets_temp)
}
else {
current <- twitter_api_call(api_url, query, api_params)
tweets_full <- fromJSON(correctJSON(current))
tweets_full <- tweets_full[keep]
}
status <- str_detect(tweets_full$created_at[nrow(tweets_full)], "2013$")
if (status) {
rm(tweets_temp)
for(r in 1:nrow(tweets_full)) {
status <- str_detect(tweets_full$created_at[r], "2013$")
if(is.na(status)) { status <- FALSE }
if(status) {
tweets_full <- tweets_full[-r,]
}
}
break
}
else {
max_id <- as.character(as.numeric(tweets_full$id_str[nrow(tweets_full)]) - 1)
loop <- loop + 1
}
}
# ---------------