PMassicotte / gtrendsR

R functions to perform and display Google Trends queries
353 stars 112 forks source link

Status code was not 200. Returned status code:429 #436

Closed ReemOmer closed 1 year ago

ReemOmer commented 1 year ago

I am trying to collect trends data for more than 5 keywords following the suggested solution on this tutorial. However, I can't get all the data due to this error: __Error_ in FUN(X[[i]], ...) : Status code was not 200. Returned status code:429_

Here is the part that generates the error:

install.packages("readr")
install.packages("colorspace")
install.packages("vctrs")
install.packages("gtrendsR")
library(gtrendsR)
keywords <- c("X", "Y", "Z", "A", "B")
country <- c("US")
time <- ("2019-10-31 2022-10-31")
trends <- gtrends(keywords, geo = country, time = time)
gittybobomber commented 1 year ago

same error, with code that used to work at least a couple of weeks ago.

PMassicotte commented 1 year ago

You should search opened issues: https://github.com/PMassicotte/gtrendsR/issues/431

As @ReemOmer already commented for the same issue with pytrends (https://github.com/GeneralMills/pytrends/issues/538), this is related to how Google block requests after a while. Please check what is 429 error is about: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429.

Google Trends do not offer a proper API, gtrendsR and pytrends are just "hacking" it to retrieve data. We do not have control on how many requests one can perform.

ReemOmer commented 1 year ago

It's me actually 😅 and wanted to know if there are any workarounds in gtrendsR. Thanks