Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 闪亮仪表板中Google Analytics API的身份验证范围问题_R_Shiny_Google Analytics Api - Fatal编程技术网

R 闪亮仪表板中Google Analytics API的身份验证范围问题

R 闪亮仪表板中Google Analytics API的身份验证范围问题,r,shiny,google-analytics-api,R,Shiny,Google Analytics Api,我正在设置一个闪亮的仪表板,通过Google Analytics Report API获取未采样的报告。这是我的第一个闪亮的项目,所以也许我的问题的解决方案很简单。不幸的是,我找不到任何对我有帮助的东西。欢迎来到我关于Stackoverflow的第一个问题: 我已经将身份验证范围设置为最高,并在自己的项目中设置了客户端web id。基本上,所有最好的练习方式都让导师对马克·爱德蒙森非常尊敬 library(shiny) # R webapps library(googleAuth

我正在设置一个闪亮的仪表板,通过Google Analytics Report API获取未采样的报告。这是我的第一个闪亮的项目,所以也许我的问题的解决方案很简单。不幸的是,我找不到任何对我有帮助的东西。欢迎来到我关于Stackoverflow的第一个问题:

我已经将身份验证范围设置为最高,并在自己的项目中设置了客户端web id。基本上,所有最好的练习方式都让导师对马克·爱德蒙森非常尊敬

    library(shiny) # R webapps
    library(googleAuthR) # auth login

# refresh authenticiaction token and set client scope

gar_set_client(web_json = "CLIENTID-JSONFILE", scopes = ("https://www.googleapis.com/auth/analytics"))

library(googleAnalyticsR) 

####################
# Shiny: USER INTERFACE
####################

# Define UI
ui <- fluidPage(

  # Authorization Login-Button
  googleAuth_jsUI("auth", login_text = "Log In"),   

  # Drop-Down Menue: Account, Property, View
  column(width=12, authDropdownUI("auth_dropdown", inColumns = FALSE)), # Modul Auswahl des Views 1 von 2
  dateRangeInput("datepicker", NULL, start = Sys.Date()-30),

  # The dimension selector (dropdown) 
  selectInput("dim", label = "Please select at least one dimension", 
              choices = dimension_options, 
              selected = c("date","hour","minute"),
              multiple = TRUE),

  # The metric dropdown
  selectInput("metric", label = "Please select at least one and maximal ten metrics", 
              choices = metric_options, 
              selected = "sessions",
              multiple = TRUE),

  # Download Button 
  downloadButton("downloadData", "Download")
                 )




####################
# Shiny: SERVER LOGIK
####################

# Define server logic
server <- function(input, output, session) {

  # get authorizatin token
  auth <- callModule(googleAuth_js,"auth") 

  # Accountliste: 
  ga_accounts <- reactive({
    req(auth())
    with_shiny(
      ga_account_list,
      shiny_access_token = auth())
    })

  # Views: Greift auf die Accountliste zu
  view_id <- callModule(authDropdown, "auth_dropdown",
                        ga.table = ga_accounts)

  # Daten abrufen
  ga_data <- reactive({
    req(view_id())
    req(input$datepicker)
    req(input$dim)
    req(input$metric)

    with_shiny(
      google_analytics,
      view_id(),
      date_range <- input$datepicker,
      metrics <- input$metric, 
      dimensions <- input$dim,      
      max = -1, #kein Sampling
      shiny_access_token = auth() 
    )
  })

  # Daten downloaden
  output$downloadData <- downloadHandler(
    filename = function() {
      paste("ViewID_",view_id(), ".csv", sep="")
    },
    content = function(file){
      write.csv2(ga_data(), file, row.names = FALSE)
    })


}

# Run the application 
shinyApp(ui = ui, server = server)
问题是,尽管代码在几天前工作,但我还是得到了以下错误代码:

Warning: Error in : API returned: Insufficient Permission: Request had insufficient authentication scopes.

  93: stop
  92: checkGoogleAPIError
  91: _f
  89: cachedHttrRequest
  88: memDoHttrRequest
  87: f
  86: gar_api_page
  85: f
  84: with_shiny
  83: <reactive:ga_accounts> [S:/GA_Report_Shiny/shinyapp_v0.R]
  67: ga.table
  66: <reactive>
  50: pList
  44: <observer>
   1: runApp

您需要列出GA帐户,这是上面GA.table函数所需要的

您需要列出GA帐户,这是上面GA.table函数所需要的

您需要了解Google Analytics Report API的第一个闪亮项目。请参阅下面我提到的API控制台支持两种类型的凭据。OAuth2.0和API密钥

    // Create the service.
            var service = new DiscoveryService(new BaseClientService.Initializer
                {
                    ApplicationName = "Discovery Sample",
                    ApiKey="[YOUR_API_KEY_HERE]",
                });

// Run the request.
            Console.WriteLine("Executing a list request...");
            var result = await service.Apis.List().ExecuteAsync();

            // Display the results.
            if (result.Items != null)
            {
                foreach (DirectoryList.ItemsData api in result.Items)
                {
                    Console.WriteLine(api.Id + " - " + api.Title);
                }
            }

您还可以参考更完整的解决方案

您需要了解Google Analytics Report API的第一个闪亮项目。请参阅下面我提到的API控制台支持两种类型的凭据。OAuth2.0和API密钥

    // Create the service.
            var service = new DiscoveryService(new BaseClientService.Initializer
                {
                    ApplicationName = "Discovery Sample",
                    ApiKey="[YOUR_API_KEY_HERE]",
                });

// Run the request.
            Console.WriteLine("Executing a list request...");
            var result = await service.Apis.List().ExecuteAsync();

            // Display the results.
            if (result.Items != null)
            {
                foreach (DirectoryList.ItemsData api in result.Items)
                {
                    Console.WriteLine(api.Id + " - " + api.Title);
                }
            }

您还可以参考更完整的解决方案

多谢各位!我的失败是,我认为Google Analytics Reporting API v4是Google Analytics API v3的更新版本,v3版本的作用域现在捆绑在v4版本中。范围列表:非常感谢!我的失败是,我认为Google Analytics Reporting API v4是Google Analytics API v3的更新版本,v3版本的作用域现在捆绑在v4版本中。作用域列表:这并不能回答@dwightkschrutell的问题。请提供完整答案,而不是链接到其他帮助页面。或者,如果您认为问题不属于此处或重复,请相应地报告问题。这甚至与问题的编码语言不同。这并没有回答@dwightkschrutell的问题。请提供完整答案,而不是链接到其他帮助页面。或者,如果您认为问题不属于此处或重复,请相应地报告问题。这甚至与问题的编码语言不同