Closed steadyfish closed 8 years ago
Sorry, but I can't reproduce. You code works for me on the Ubuntu Server 14.04.4.
> sessionInfo()
R version 3.2.4 (2016-03-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.4 LTS
locale:
[1] LC_CTYPE=ru_RU.UTF-8 LC_NUMERIC=C
[3] LC_TIME=ru_RU.UTF-8 LC_COLLATE=ru_RU.UTF-8
[5] LC_MONETARY=ru_RU.UTF-8 LC_MESSAGES=ru_RU.UTF-8
[7] LC_PAPER=ru_RU.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=ru_RU.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RGA_0.4.1 httr_1.1.0
loaded via a namespace (and not attached):
[1] R6_2.1.2 curl_0.9.6 lubridate_1.5.0 stringr_0.6.2
[5] jsonlite_0.9.19 openssl_0.9.2
> httr::with_verbose(get_ga(id))
-> GET /oauth2/v1/tokeninfo?access_token=ya29.pAJUN8jWfBQgyePcg4DoQvHbSRgjw1-m0hSUMjr-N7JbU_jbHWHuQd6mUgeJsf9hJg HTTP/1.1
-> User-Agent: libcurl/7.35.0 r-curl/0.9.6 httr/1.1.0
-> Host: www.googleapis.com
-> Accept-Encoding: gzip, deflate
-> Accept: application/json
->
<- HTTP/1.1 200 OK
<- Cache-Control: no-cache, no-store, max-age=0, must-revalidate
<- Pragma: no-cache
<- Expires: Fri, 01 Jan 1990 00:00:00 GMT
<- Date: Mon, 14 Mar 2016 23:06:57 GMT
<- Vary: Origin
<- Vary: X-Origin
<- Content-Type: application/json; charset=UTF-8
<- Content-Encoding: gzip
<- X-Content-Type-Options: nosniff
<- X-Frame-Options: SAMEORIGIN
<- X-XSS-Protection: 1; mode=block
<- Server: GSE
<- Alternate-Protocol: 443:quic,p=1
<- Alt-Svc: quic=":443"; ma=2592000; v="31,30,29,28,27,26,25"
<- Transfer-Encoding: chunked
<-
-> GET /oauth2/v1/tokeninfo?access_token=ya29.pAJUN8jWfBQgyePcg4DoQvHbSRgjw1-m0hSUMjr-N7JbU_jbHWHuQd6mUgeJsf9hJg HTTP/1.1
-> User-Agent: libcurl/7.35.0 r-curl/0.9.6 httr/1.1.0
-> Host: www.googleapis.com
-> Accept-Encoding: gzip, deflate
-> Accept: application/json
->
<- HTTP/1.1 200 OK
<- Cache-Control: no-cache, no-store, max-age=0, must-revalidate
<- Pragma: no-cache
<- Expires: Fri, 01 Jan 1990 00:00:00 GMT
<- Date: Mon, 14 Mar 2016 23:06:58 GMT
<- Vary: Origin
<- Vary: X-Origin
<- Content-Type: application/json; charset=UTF-8
<- Content-Encoding: gzip
<- X-Content-Type-Options: nosniff
<- X-Frame-Options: SAMEORIGIN
<- X-XSS-Protection: 1; mode=block
<- Server: GSE
<- Alternate-Protocol: 443:quic,p=1
<- Alt-Svc: quic=":443"; ma=2592000; v="31,30,29,28,27,26,25"
<- Transfer-Encoding: chunked
<-
-> GET /analytics/v3/data/ga?ids=ga%3A7783180&start-date=7daysAgo&end-date=yesterdcs=ga%3Ausers%2Cga%3Asessions%2Cga%3Apageviews&start-index=1&max-results=10000 HTT
-> User-Agent: libcurl/7.35.0 r-curl/0.9.6 httr/1.1.0
-> Host: www.googleapis.com
-> Accept-Encoding: gzip, deflate
-> Accept: application/json
-> Authorization: Bearer ya29.pAJUN8jWfBQgyePcg4DoQvHbSRgjw1-m0hSUMjr-N7JbU_jbHWHusf9hJg
->
<- HTTP/1.1 200 OK
<- Expires: Mon, 14 Mar 2016 23:06:59 GMT
<- Date: Mon, 14 Mar 2016 23:06:59 GMT
<- Cache-Control: private, max-age=0, must-revalidate, no-transform
<- ETag: "RTuqIyS1Tt5XEFy6I77L5pEAbZQ/5QuRSc-jJxzrrm-UlTAaR9Y-riw"
<- Vary: Origin
<- Vary: X-Origin
<- Content-Type: application/json; charset=UTF-8
<- X-Content-Type-Options: nosniff
<- X-Frame-Options: SAMEORIGIN
<- X-XSS-Protection: 1; mode=block
<- Content-Length: 1144
<- Server: GSE
<- Alternate-Protocol: 443:quic,p=1
<- Alt-Svc: quic=":443"; ma=2592000; v="31,30,29,28,27,26,25"
<-
users sessions pageviews
1 43873 91583 462445
@artemklevtsov Thanks for a quick response!
I tried this code as "root" user on command line R on Ubuntu and it worked. This seems to be an issue with RStudio server.. This is probably specific to my user settings on the system.
@artemklevtsov On debugging this further (on rstudio server), I figured the error to be happening because of (lack of) implicit type conversion in encode()
function inside compose_query()
function:
encode <- function(x) {
if (inherits(x, "AsIs")) return(x)
curl::curl_escape(x)
}
values <- vapply(elements, encode, character(1))
At this point, some of the attributes in elements
list contain numeric value (e.g. start-index
, max-results
). This results in an error on calling curl::curl_escape()
, as it is expecting a character. Would one expect numeric values to be coerced to character here?
A possible way out would be to do explicit conversion to character:
curl::curl_escape(as.character(x))
Any thoughts?
(For now, I am avoiding this error by passing start.index
and max.results
to list_profiles
but this won't work when max.results
is more than 1K/10K depending on which API is being called ):
ga_profiles = list_profiles(token = token, start.index = "1", max.results = "1000")
But curl::curl_escape
auto convert a numeric types:
curl::curl_escape(1L)
#> [1] "1"
curl::curl_escape(2)
#> [1] "2"
Do you try update the curl
package?
packageVersion("curl")
#> [1] ‘0.9.6’
You are right. Updating curl
to latest CRAN version did the trick. Thanks!
Code:
This same code works well on a windows machine.
Verbose output:
Version info: