Skip to content

Commit

Permalink
Update fbGetMarketingStat.R
Browse files Browse the repository at this point in the history
  • Loading branch information
selesnow authored Dec 21, 2017
1 parent 8cd3523 commit 6864f2e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions R/fbGetMarketingStat.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

fbGetMarketingStat2 <-
fbGetMarketingStat <-
function(accounts_id = NULL,
sorting = NULL,
level = "account",
Expand Down Expand Up @@ -32,6 +31,7 @@ fbGetMarketingStat2 <-

#API request counter
request_counter <- 0
error_counter <- 0

for(i in 1:length(accounts_id)){

Expand Down Expand Up @@ -64,6 +64,8 @@ fbGetMarketingStat2 <-

#Check answer on errors
if (!is.null(answerobject$error)) {
#Add error in error counter
error_counter <- error_counter + 1
if (answerobject$error$message == "(#17) User request limit reached") {
#First attempt
attempt <- 1
Expand All @@ -89,7 +91,8 @@ fbGetMarketingStat2 <-
if(console_type == "message"){
packageStartupMessage("Problem fixed. Continue data collection", appendLF = T)}
break}

#Add error in error counter
error_counter <- error_counter + 1
#Next attempt
attempt <- attempt + 1
}
Expand Down Expand Up @@ -118,6 +121,8 @@ fbGetMarketingStat2 <-

#Check answer on errors
if (!is.null(answerobject$error)) {
#Add error in error counter
error_counter <- error_counter + 1
if (answerobject$error$message == "(#17) User request limit reached") {
#First attempt
attempt <- 1
Expand All @@ -143,7 +148,8 @@ fbGetMarketingStat2 <-
if(console_type == "message"){
packageStartupMessage("Problem fixed. Continue data collection", appendLF = T)}
break}

#Add error in error counter
error_counter <- error_counter + 1
#Next attempt
attempt <- attempt + 1
}
Expand Down Expand Up @@ -174,6 +180,7 @@ fbGetMarketingStat2 <-
packageStartupMessage("Data loaded successfully!", appendLF = T)
packageStartupMessage(paste0("Loaded ",nrow(result)," rows."), appendLF = T)
packageStartupMessage(paste0("Sended ",request_counter," API requests."), appendLF = T)
if(error_counter > 0) packageStartupMessage(paste0(error_counter," error request."), appendLF = T)
packageStartupMessage("-----------------------------------------------------", appendLF = T)
return(result)
}

0 comments on commit 6864f2e

Please sign in to comment.