artemklevtsov / RGA

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

Error: oauth_listener() needs an interactive environment. #20

Closed chipoglesby closed 8 years ago

chipoglesby commented 8 years ago

Hi @artemklevtsov, I'm trying to create a file that can be ran via cron job. It's basically just:

knitr::knit('report.Rmd').

When I run it in terminal, this is the error that I get:

Client ID and Client secret loaded from environment variables. Access token will be stored in the '.ga-token.rds' file. Error: oauth_listener() needs an interactive environment. Execution halted

In the RMD file, I've called library(RGA) and authorize() and I've also tried authorize(cache=TRUE, reauth=TRUE) but I still get the error.

Do you have any ideas why this may be happening and how I can fix it?

Thank you.

artemklevtsov commented 8 years ago

Try the following steps:

library(RGA)
authorize(client.id = " MyClientID", client.secret = "MyClientSecret", cache = "/projdir/ga-token")
---
title: "Untitled"
output: html_document
---
```{r}
library(RGA)
authorize(client.id = " MyClientID", client.secret = "MyClientSecret", cache = "/projdir/ga-token")
list_accounts()
 ```

Note that when the OAuth token refreshed R-session rewrite the cache file. So you need write permissions for this file,

~ % Rscript -e 'knitr::knit("/tmp/test.Rmd")'                  :(
processing file: /tmp/test.Rmd
  |................................                                 |  50%
  ordinary text without R code
  |.................................................................| 100%
label: unnamed-chunk-1
output file: test.md
[1] "test.md"
chipoglesby commented 8 years ago

Thank you, I'll try this now.

chipoglesby commented 8 years ago

This works. Thank you @artemklevtsov for your help!