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)
This works for me:
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
Maybe update your packages and/or the oauth endpoints?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.