Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

r

gtrendsr

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.

like image 432
OGC Avatar asked Sep 10 '25 14:09

OGC


2 Answers

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

like image 196
OGC Avatar answered Sep 13 '25 03:09

OGC


For anyone still having this problem in May 2025, upgrading to the latest gtrendsR dev version helped:

install.packages("remotes")
remotes::install_github("PMassicotte/gtrendsR")
like image 22
broti Avatar answered Sep 13 '25 03:09

broti