htmlrgtrendsr

gtrends Error Version 2: Error in interest_over_time(widget, comparison_item, tz) : Status code was not 200. Returned status code:401


I have been trying to pull Covid data from Gtrends but I am getting the following error:

I am using the grendsR package in R.

# google search for covid (week started XX - SUN): https://trends.google.com/trends/explore?geo=US-HI&q=covid
search_covid <- gtrends(keyword = 'covid', geo = 'US-HI', time = 'today+5-y') %>%
  pluck("interest_over_time") %>%
  as_tibble() %>%
  select(date, hits) %>%
  rename(search_covid = hits) %>%
  mutate(date = ymd(date) + days(1),
         search_covid = as.numeric(search_covid %>% ifelse(. == '<1', 0, .)))
search_covid %>% ts_plot()
search_covid %>% tail()

I am getting this error: Error in interest_over_time(widget, comparison_item, tz) : Status code was not 200. Returned status code:401

Any help would be appreciated.


Solution

  • Reloading the gtrendsR package to the newer version seemed to have solved this problem:

    install.packages("readr")
    install.packages("colorspace")
    install.packages("vctrs")
    install.packages("gtrendsR")
    

    Solution found from here: How to load google trends package in R