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
• 10,380 points
52 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,020 points

Related Questions In Data Analytics

0 votes
1 answer
0 votes
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,020 points
20 views
0 votes
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,020 points
252 views
0 votes
1 answer
0 votes
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,020 points
245 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,020 points
22 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,020 points
66 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,020 points
199 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.