【问题标题】:Data Mining of Google Analytics using R使用 R 对 Google Analytics 进行数据挖掘
【发布时间】:2016-12-30 07:11:22
【问题描述】:

我正在尝试使用此代码访问我的 Google Analytics API,但在运行代码后出现此错误

init_oauth2.0 中的错误(self$endpoint, self$app, scope = self$params$scope. 未经授权 (HTTP 401)。获取访问令牌失败。

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)

【问题讨论】:

  • 您使用的是 googleAuthR,但它支持的 Google Analytics 库是 googleAnalyticsR,而不是 RGoogleAnalytics

标签: r oauth google-api google-oauth google-analytics-api


【解决方案1】:

这对我有用:

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

也许更新您的软件包和/或 oauth 端点?

【讨论】:

    猜你喜欢
    • 2015-05-15
    • 2018-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 2012-05-01
    • 2012-06-21
    相关资源
    最近更新 更多