Error saying Failed to get an access token when trying to access my Google Analytics API

0 votes

I am trying to use this code to access my Google Analytics API, but after running the code I get this error

Error in init_oauth2.0(self$endpoint, self$app, scope = self$params$scope. Unauthorized (HTTP 401). Failed to get an access token.

install.packages("RGoogleAnalytics")
install.packages("googleAuthR")
library(RGoogleAnalytics)
# Authorize the Google Analytics account

client.id <- "########################.com"
client.secret <- "#################_TknUI"
token<-Auth(client.id,client.secret)
Nov 15, 2018 in Data Analytics by Ali
• 11,360 points
1,029 views

1 answer to this question.

0 votes

Try this:

library(RGoogleAnalytics)
oauth_token <- Auth(
  client.id = "XXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com", 
  client.secret = "XXXXXXXXXXXXXXXXX"
)
oauth_token
# <Token>
#   <oauth_endpoint>
#   authorize: https://accounts.google.com/o/oauth2/auth
# access:    https://accounts.google.com/o/oauth2/token
# validate:  https://www.googleapis.com/oauth2/v1/tokeninfo
# revoke:    https://accounts.google.com/o/oauth2/revoke
# <oauth_app> google
# key:    XXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com
# secret: <hidden>
#   <credentials> access_token, expires_in, refresh_token, token_type
# ---


sessionInfo()
# R version 3.3.2 (2016-10-31)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 7 x64 (build 7601) Service Pack 1
# 
# locale:
#   [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
# [4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] RGoogleAnalytics_0.1.1 httr_1.2.1             lubridate_1.6.0       
# 
# loaded via a namespace (and not attached):
#   [1] R6_2.2.0      magrittr_1.5  tools_3.3.2   stringi_1.1.2 stringr_1.1.0
answered Nov 15, 2018 by Maverick
• 10,840 points

Related Questions In Data Analytics

0 votes
1 answer
+1 vote
1 answer

an error occurred" because rows do not match when trying to use lm to perform an ANOVA test

Maybe you could do something like this. ...READ MORE

answered Nov 2, 2018 in Data Analytics by Maverick
• 10,840 points
588 views
+1 vote
1 answer

Error saying cannot open file 'file.pdf' when trying to save a plot in ggplot

You could try adding the following line ...READ MORE

answered Nov 9, 2018 in Data Analytics by Maverick
• 10,840 points
7,541 views
+1 vote
1 answer
+1 vote
1 answer

Error saying "vector size cannot be NA" when using R with data mining

You can use the removesparseterm function.  Removes sparse ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,840 points
4,368 views
+1 vote
2 answers
0 votes
1 answer

Trying to find frequent itemsets of a data set using arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", "milk", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,840 points
549 views
0 votes
1 answer

Error saying "Error in df$item : object of type 'closure' is not subsettable" when trying to use arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,840 points
1,414 views
0 votes
1 answer

Error saying "duplicate 'row.names' are not allowed" when trying to setup my data for the mlogit-package

Take out the chid.var argument in your call to mlogit.data, ...READ MORE

answered Nov 12, 2018 in Data Analytics by Maverick
• 10,840 points
1,753 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP