#install.packages("searchConsoleR")
#install.packages("googleAuthR")
library(searchConsoleR)
library(googleAuthR)
## 2019-03-23 19:34:45> No scopes have been set, set them via 
##               options(googleAuthR.scopes.selected) - 
##               no authentication attempted.
gar_auth_service(
  json_file = "/home/tom/rstudio-195817-35c1889dc25c.json",
  scope = "https://www.googleapis.com/auth/webmasters"
)
start <- Sys.Date() - 5
## one days data, but change it as needed
end <- Sys.Date() - 5 
## change this to the website you want to download data for. Include http
website <- "https://tom.alby.de"
download_dimensions <- c('query','page')
type <- c('web')
sc_data <- search_analytics(siteURL = website, 
                         startDate = start, 
                         endDate = end, 
                         dimensions = download_dimensions, 
                         searchType = type)
## Fetching search analytics for url: https://tom.alby.de dates: 2019-03-18 2019-03-18 dimensions: query page dimensionFilterExp:  searchType: web aggregationType: auto
sc_data[7] <- website
sc_data[8] <- start
colnames(sc_data)[7] <- "website"
colnames(sc_data)[8] <- "date"
sc_data