artemklevtsov / RGA

A Google Analytics API client for R
http://cran.r-project.org/package=RGA
32 stars 13 forks source link

'Error: is.request(y) is not TRUE' error with RGA 0.2.4 from CRAN #1

Closed DamienCormann closed 8 years ago

DamienCormann commented 9 years ago

After a library update from RGA library to 0.2.4, the below error message is returned by R when I fetch data:

Error: is.request(y) is not TRUE

It happens when using RStudio or in batch mode.

This is my previously working code:

firstdate(profile.id = profile_ID, token = ga_token_RGA)

and

get_ga(profile.id = profile_ID , 
    start.date = "500daysAgo", 
    end.date = "yesterday", 
    metrics = "ga:users,ga:sessions", 
    dimensions = "ga:date", 
    token = ga_token_RGA)

here is a example with traceback from a fresh session

> library("RGA")
> profile_ID <-  ******************
> first_date <- as.character(firstdate(profile.id = profile_ID, token = ga_token_RGA))
Error: is.request(y) is not TRUE
> traceback()
16: stop(sprintf(ngettext(length(r), "%s is not TRUE", "%s are not all TRUE"), 
        ch), call. = FALSE, domain = NA)
15: stopifnot(is.request(x), is.request(y))
14: f(init, x[[i]])
13: Reduce(request_combine, list(...))
12: c.request(req, token$sign(req$method, req$url))
11: c(req, token$sign(req$method, req$url))
10: request_prepare(req)
9: request_perform(req, hu$handle$handle)
8: GET(url, query = query, accept_json(), config)
7: get_response(type = type, path = path, query = query, token = token)
6: get_data(type = type, query = query, token = token)
5: get_report(type = "ga", query = query, token = token)
4: get_ga(profile.id = profile.id, start.date = "2005-01-01", end.date = "today", 
       metrics = "ga:sessions", dimensions = "ga:date", filters = "ga:sessions>0", 
       max.results = 1L, token = token)
3: withCallingHandlers(expr, warning = function(w) invokeRestart("muffleWarning"))
2: suppressWarnings(get_ga(profile.id = profile.id, start.date = "2005-01-01", 
       end.date = "today", metrics = "ga:sessions", dimensions = "ga:date", 
       filters = "ga:sessions>0", max.results = 1L, token = token))
1: firstdate(profile.id = profile_ID, token = ga_token_RGA)
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS release 6.6 (Final)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RGA_0.2.4

loaded via a namespace (and not attached):
 [1] httr_1.0.0      R6_2.1.1        magrittr_1.5    tools_3.2.2     curl_0.9.3      Rcpp_0.12.1     stringi_0.5-5  
 [8] jsonlite_0.9.17 stringr_1.0.0   httpuv_1.3.3   

as it seems to be httr related, I tried to devolute httr using:

remove.packages("httr")
install.packages("http://cran.r-project.org/src/contrib/Archive/httr/httr_0.6.1.tar.gz", repos=NULL, type="source")

But RGA required version 1.0.0

> library("RGA")
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 
  namespace ‘httr’ 0.6.1 is already loaded, but >= 1.0.0 is required
Error: package or namespace load failed for ‘RGA’
artemklevtsov commented 9 years ago

Please try the following code:

token <- RGA::authorize()
id <- ********** # without "ga:"
u <- paste0("https://www.googleapis.com/analytics/v3/data/ga?ids=ga:", id, "&start-date=2005-01-01&end-date=today&metrics=ga:sessions&dimensions=ga:date&filters=ga:sessions>0&max-results=1")
httr::GET(u, httr::config(token = token), httr::accept_json())
query <- list(ids = paste0("ga:", id), `start-date` = "2005-01-01", `end-date` = "today", metrics = "ga:sessions", dimensions = "ga:date", filters = "ga:sessions>0", `max-results` = 1)
httr::GET("https://www.googleapis.com/analytics/v3/data/ga", query = query, httr::config(token = token), httr::accept_json())
DamienCormann commented 9 years ago

Hello Artem and thanks for your help here is the result:

token <- ga_token_RGA # copy my personal  token to the token environement (the token was working previously)  
id <- nnnnnnnn # actually a eight digit number  
u <- paste0("https://www.googleapis.com/analytics/v3/data/ga?ids=ga:", id, "&start-date=2005-01-01&end-date=today&metrics=ga:sessions&dimensions=ga:date&filters=ga:sessions>0&max-results=1")  
httr::GET(u, httr::config(token = token), httr::accept_json())
Error: is.request(y) is not TRUE
httr::GET("https://www.googleapis.com/analytics/v3/data/ga", query = query, httr::config(token = token), httr::accept_json())
Error: is.character(query) is not TRUE

kind regards

artemklevtsov commented 9 years ago

My code example works for me. So you have strange bug which not related with the RGA package: it's httr 1.0.0 issue. You should send bug report to the httr bug tracker. Now I can't reproduce you issue.

Below I provide the reproducible example code for you:

library(httr)
token <- oauth2.0_token(
    endpoint = oauth_endpoints("google"),
    app = oauth_app(appname = "app",
                    key = "144394141628-8m5i5icva7akegi3tp6215d9eg9o5cln.apps.googleusercontent.com",
                    secret = "wlFmhluHqTdZw6UG22h5A2nr"),
    scope = "https://www.googleapis.com/auth/analytics.readonly",
    cache = FALSE)
id <- 83639328
u <- paste0("https://www.googleapis.com/analytics/v3/data/ga?ids=ga:", id, "&start-date=2005-01-01&end-date=today&metrics=ga:sessions&dimensions=ga:date&filters=ga:sessions>0&max-results=1")
GET(u, config(token = token))
sessionInfo()
DamienCormann commented 8 years ago

thanks for your help

artemklevtsov commented 8 years ago

I tested RGA package on the CentOS 6.6 docker image. I didn't reproduce your issue.