Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-authentication JSON file not working / Account list parsing fail #41

Closed
mischa2002k2 opened this issue Sep 28, 2016 · 11 comments
Closed
Labels

Comments

@mischa2002k2
Copy link

mischa2002k2 commented Sep 28, 2016

Hi,
maybe I'm just not fully integrating the authentication process. But as I followed the setup the only thing I need to do is to place the .json from Google APIs Admin Console and point to it with the Global variable.

Sys.setenv(GA_AUTH_FILE = "/Users/michaelsinner/rStudio/test/auth/myAuth.json")

When I try to run a simple test code I get this error:
No authorization yet in this session!
NOTE: a .httr-oauth file exists in current working directory.
Run gar_auth() to use the credentials cached for this session.
Token doesn't exist
Fehler in acc_sum() : Invalid Token
Zusätzlich: Warnmeldung:
In checkTokenAPI(shiny_access_token) : Invalid local token

What am I missing? Is there an issue with the auto authentication with JSON file?

@MarkEdmondson1234
Copy link
Collaborator

Can you try deleting or moving the existing .httr-oauth file in your folder? It may be confusing the auto auth run, but I may also need to improve the logic.

@mischa2002k2
Copy link
Author

Hi Mark,

I tried this already, the error message keeps a little bit the same. Here it is:

No authorization yet in this session!
No .httr-oauth file exists in current working directory. Run gar_auth() to provide credentials.
Token doesn't exist
Fehler in acc_sum() : Invalid Token
Zusätzlich: Warnmeldung:
In checkTokenAPI(shiny_access_token) : Invalid local token

@MarkEdmondson1234
Copy link
Collaborator

MarkEdmondson1234 commented Sep 29, 2016

The error suggests its not finding the file you are specifying at that filepath.

You can check to see if you can load it via:

library(jsonlite)
fromJSON(path_to_your_json)

..and you can autheticate directly using

googleAuthR::gar_auth_service("my_key.json")

May I also see your sessionInfo:

> sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] googleAnalyticsR_0.3.0.9000

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.7                    magrittr_1.5                   googleCloudStorageR_0.2.0.9000 devtools_1.12.0.9000          
 [5] xtable_1.8-2                   R6_2.1.3                       bigQueryR_0.2.0.9000           httr_1.2.1.9000               
 [9] dplyr_0.5.0                    tools_3.3.0                    DBI_0.4-1                      googleAuthR_0.4.0.9000        
[13] withr_1.0.2                    htmltools_0.3.5                digest_0.6.10                  assertthat_0.1                
[17] tibble_1.1                     tidyjson_0.2.1                 crayon_1.3.1                   shiny_0.14                    
[21] rsconnect_0.4.3                testthat_1.0.2                 memoise_1.0.0                  mime_0.5    

Also try putting the file in the .Renviron file in your computers user's home directory.

@mischa2002k2
Copy link
Author

mischa2002k2 commented Sep 29, 2016

Hey Mark,

this is really strange... I used this:

googleAuthR::gar_auth_service(Sys.getenv("GA_AUTH_FILE"))

(btw: the file is there, I tried to load it into JSON object and it works 👍 )

Now the auth seems to work (but not quite). Now appeared this:

> account_list <- google_analytics_account_list()
Error : df is not a data frame
Warnmeldung:
In acc_sum() :
  API Data failed to parse.  Returning parsed from JSON content.
                    Use this to test against your data_parse_function.

This is my sessionInfo:

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)

locale:
[1] de_DE.UTF-8/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8

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

other attached packages:
[1] jsonlite_1.1           googleAnalyticsR_0.3.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.7               magrittr_1.5              googleCloudStorageR_0.2.0 devtools_1.12.0           xtable_1.8-2             
 [6] R6_2.1.3                  bigQueryR_0.2.0           httr_1.2.1                dplyr_0.5.0               tools_3.3.1              
[11] DBI_0.5-1                 googleAuthR_0.4.0         withr_1.0.2               htmltools_0.3.5           digest_0.6.10            
[16] assertthat_0.1            tibble_1.2                tidyjson_0.2.1            crayon_1.3.2              shiny_0.14               
[21] testthat_1.0.2            memoise_1.0.0             mime_0.5                  httpuv_1.3.3   

@MarkEdmondson1234
Copy link
Collaborator

MarkEdmondson1234 commented Sep 29, 2016

Ah, looks like you have CRAN version of googleAnalyticsRloaded, when you need the github version to use auto-auth for the moment until I put it on CRAN

devtools::install_github("MarkEdmondson1234/googleAnalyticsR")

The account parsing though looks like a different issue. If possible could you do a str(account_list) to show what it returned instead of the data.frame. The parsing fails if there is something unexpected in there, such as an account without a web-property, that I've had problems with before and thought I caught, but looks like there is still some edge case where it doesn't work ;( you do at least get the data, just not in a user-friendly format.

@MarkEdmondson1234 MarkEdmondson1234 changed the title Auto-authentication JSON file not working Auto-authentication JSON file not working / Account list parsing fail Sep 29, 2016
@mischa2002k2
Copy link
Author

mischa2002k2 commented Sep 29, 2016

This is still strange: I installed your version from github, when I now invoke "library(googleAnalyticsR)" it will use automatically your version? Or do I have to refer to it any other way?

The auto-authentication is not working with this approach.

If the authentication is now made with my JSON (it works with googleAuthR::gar_auth_service(Sys.getenv("GA_AUTH_FILE")))

str(account_list) is NULL

The user is my service account r-xxxxx-yyyyy@zzzzzzz.iam.gserviceaccount.com

This one is admin level in one GA account (on account level checked: manage users, etc.).

@mischa2002k2
Copy link
Author

Hi Mark,
I played around with the account_list function, and it seems there is some issue with the number of available accounts/properties/views. When the service account user is only admin in one account with one property and one view there will be this "df is not a data frame" error.
However if I add the user to multiple accounts the functions works fine for me.

Hope this helps debugging. Really appreciate your work!

@MarkEdmondson1234
Copy link
Collaborator

Thanks @mischa2002k2 , this will help. I wonder if it fails for all 1 length data.frames.

@MarkEdmondson1234
Copy link
Collaborator

@mischa2002k2 I think your two issues here should now be solved using the current github version, namely auto-auth and single row account summary lists. Reopen if that is not the case.

@changyeli
Copy link

Hello, I had exactly same error here and I tried all methods mentioned above but I still got the same error message (API Data failed to parse). Do you have any suggestion for this? Thanks in advance.

@MarkEdmondson1234
Copy link
Collaborator

@palooney could you please open it with a new issue and an example of your code, along with the output of sessionInfo. Please also run the code with this option set: options(googleAuthR.verbose = 2) and edit out anything sensitive.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants