MarkEdmondson1234 / searchConsoleR

R interface with Google Search Console API v3, including Search Analytics.
http://code.markedmondson.me/searchConsoleR/
Other
114 stars 41 forks source link

Is native.json overwriting options? #37

Closed chipoglesby closed 6 years ago

chipoglesby commented 6 years ago

I was reading through the documentation and I'm curious if the settings in inst/clients/native.json are overwriting when you set options() a R file like:

options("searchConsoleR.client_id" = "YOUR_CLIENT_ID")
options("searchConsoleR.client_secret" = "YOUR_CLIENT_SECRET")

Here's an example of my code, but when I go to authenticate, I'm taken to the Google Cloud Console settings that are listed in inst/clients/native.json instead of what I've used in options.

library(searchConsoleR)
library(tidyverse)
library(googleAuthR)

options("searchConsoleR.client_id" = "xxx")
options("searchConsoleR.client_secret" = "xxx")

scr_auth(token = '.httr-oauth')

startDate <- as.Date(Sys.Date() - 10)
endDate <- as.Date(Sys.Date() - 3)

while (startDate <= endDate) {
  queries <- search_analytics('http://www.chipoglesby.com',
                              endDate, endDate,
                              c("date","query","page","country", "device"), 
                              walk_data = "byBatch",
                              rowLimit = 20000) %>% 
    mutate(device = tolower(as.factor(device))) %>% 
    write_csv(paste0('data/', 'chipoglesby', startDate, '.csv'))
    startDate <- startDate + 1                  
}
MarkEdmondson1234 commented 6 years ago

Yes, at the moment the native client Id/secret options are run when you use scr_auth() - if you want to avoid that you could use googleAuthR::gar_auth() for more customisation.

Since the webmasters API is a lot more generous we've never seen the need to require people to use their own client Id, and I think the assumption is if you require that then you are ok with the more technical but customised solution using googleAuthR::gar_auth() directly, but let me know if this is off :)

MarkEdmondson1234 commented 6 years ago

If interested, the API limits are 100 million a day, 2000 calls per 100 seconds per user, which we're way under globally.

chipoglesby commented 6 years ago

Okay. It sounds like scr_auth() might work. I just have to reauthenticate each day when I run my script. I'm trying to automate this process, but it's not working because I always have to open my browser and get a new token.

MarkEdmondson1234 commented 6 years ago

If you specify the filename, it should refresh itself:

scr_auth("my_token.oauth")
chipoglesby commented 6 years ago

Thanks @MarkEdmondson1234, I'll try that.