我必须建立一个Shiny-Board,我需要从Google Analytics Reporting API获得超过10k行。为此,我使用自己的Google API-Project 在RStudio中执行此操作非常完美,我可以获得所需的行数。如果我在闪亮的情况下执行此操作,我不会遇到问题,如果我想获得更多,那么获得的行数少于10k我会得到以下错误:
2017-08-17 14:12:55> Fetched: landingPagePath city date sourceMedium sessions newUsers bounceRate pageviewsPerSession avgSessionDuration transactions transactionRevenue. [10000] total results out of a possible [190119], Start-Index: 1
2017-08-17 14:12:55> Batching data into [20] calls.
Request #: 1 : 10001 : 20001 : 30001 : 40001 : 50001 : 60001 : 70001 : 80001 : 90001
2017-08-17 14:12:57> Request to profileId: ()
Warning: Error in f: Invalid dimension or metric:
Stack trace (innermost first):
114: f
113: FUN
112: lapply
111: googleAuthR::gar_batch
110: FUN
109: lapply
108: googleAuthR::gar_batch_walk
107: batchData
106: loop_ids
105: f
104: with_shiny
103: eventReactiveHandler [#405]
83: gadata
82: renderDataTable [#511]
81: func
80: origRenderFunc
79: output$Con_Table
4: <Anonymous>
3: do.call
2: print.shiny.appobj
1: <Promise>
我可以在不同的时间范围内调用相同的查询(不要达到10k限制),它可以使用维度和指标。
这是我使用的查询:
options("googleAuthR.webapp.client_id" = app_config$gaClientId)
options("googleAuthR.webapp.client_secret" = app_config$gaClientSecret)
options("googleAuthR.scopes.selected" =c("https://www.googleapis.com/auth/analytics.readonly"))
## Get auth code from return URL
token <- callModule(googleAuth, "login")
ga_accounts <- reactive({
req(token())
with_shiny(ga_account_list, shiny_access_token = token())
})
selected_id <- callModule(authDropdown, "auth_menu", ga.table = ga_accounts)
ga<-with_shiny(google_analytics,
id = gaid,
start=(as.character(input$datestart)), end=(as.character(input$dateend)),
metrics = metric,
dimensions = dime,max=99999999,
shiny_access_token = token())
更多信息:
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
> packageVersion("googleAnalyticsR")
[1] ‘0.4.1’
有人知道我错过了什么吗?
答案 0 :(得分:1)
感谢Mark Edmondson,问题解决了。而不是使用V3版本的API只需使用V4版本。电话看起来像这样:
ga<-with_shiny(google_analytics_4,
id = gaid,
date_range = c(as.character(input$datestart), as.character(input$dateend)),
metrics = metric,
dimensions = dime,anti_sample = TRUE,
shiny_access_token = token())