Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any keyword with "&" character triggers "widget$status_code == 200" error #267

Closed
dripti opened this issue Apr 13, 2018 · 7 comments
Closed

Comments

@dripti
Copy link

dripti commented Apr 13, 2018

Trends <- gtrends("Bath & body works",geo =US )

Sys.getlocale()
[1] "LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252"
sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] xlsx_0.5.7 xlsxjars_0.6.1 rJava_0.9-8 dplyr_0.7.4 gtrendsR_1.4.2 Rmazon_0.2 devtools_1.13.5

loaded via a namespace (and not attached):
[1] Rcpp_0.12.14 compiler_3.4.1 pillar_1.1.0 git2r_0.19.0 plyr_1.8.4
[6] bindr_0.1 tools_3.4.1 digest_0.6.12 anytime_0.3.0 jsonlite_1.5
[11] memoise_1.1.0 tibble_1.4.2 gtable_0.2.0 pkgconfig_2.0.1 rlang_0.2.0
[16] curl_3.1 yaml_2.1.14 parallel_3.4.1 bindrcpp_0.2 withr_2.1.0
[21] httr_1.3.1 stringr_1.3.0 xml2_1.2.0 grid_3.4.1 glue_1.2.0
[26] R6_2.2.2 pbapply_1.3-4 XML_3.98-1.9 ggplot2_2.2.1 selectr_0.3-1
[31] magrittr_1.5 scales_0.5.0 assertthat_0.2.0 rvest_0.3.2 RApiDatetime_0.0.3
[36] colorspace_1.3-2 labeling_0.3 stringi_1.1.6 lazyeval_0.2.0 munsell_0.4.3

@tokumotion
Copy link

tokumotion commented May 2, 2018

Similar issue here, trying to get a basic query:

gtrends(keyword = c('toyota', 'yaris', 'corolla'), time = '2017-04-30 2018-04-29', geo = 'PE')
Error in get_widget(comparison_item, category, gprop, hl) : 
  widget$status_code == 200 is not TRUE

Sys.getlocale()
[1] "en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8"

packageVersion('gtrendsR')
[1] ‘1.4.2’

Session info:

> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] gtrendsR_1.4.2  scales_0.5.0    corrplot_0.84   lubridate_1.7.4
 [5] forcats_0.3.0   stringr_1.3.0   dplyr_0.7.4     purrr_0.2.4    
 [9] readr_1.1.1     tidyr_0.8.0     tibble_1.4.2    ggplot2_2.2.1  
[13] tidyverse_1.2.1

loaded via a namespace (and not attached):
 [1] reshape2_1.4.3     haven_1.1.1        lattice_0.20-35   
 [4] colorspace_1.3-2   yaml_2.1.19        rlang_0.2.0       
 [7] pillar_1.2.2       foreign_0.8-70     glue_1.2.0        
[10] withr_2.1.2        modelr_0.1.1       readxl_1.1.0      
[13] bindrcpp_0.2.2     bindr_0.1.1        plyr_1.8.4        
[16] munsell_0.4.3      gtable_0.2.0       anytime_0.3.0     
[19] cellranger_1.1.0   rvest_0.3.2        devtools_1.13.5   
[22] psych_1.8.3.3      memoise_1.1.0      parallel_3.5.0    
[25] curl_3.2           broom_0.4.4        Rcpp_0.12.16      
[28] jsonlite_1.5       mnormt_1.5-5       hms_0.4.2         
[31] digest_0.6.15      stringi_1.1.7      grid_3.5.0        
[34] cli_1.0.0          tools_3.5.0        magrittr_1.5      
[37] lazyeval_0.2.1     crayon_1.3.4       RApiDatetime_0.0.3
[40] pkgconfig_2.0.1    xml2_1.2.0         assertthat_0.2.0  
[43] httr_1.3.1         rstudioapi_0.7     R6_2.2.2          
[46] nlme_3.1-137       compiler_3.5.0   

@PMassicotte
Copy link
Owner

Hard to tell, the last one works for me.

plot(gtrendsR::gtrends(keyword = c('toyota', 'yaris', 'corolla'), time = '2017-04-30 2018-04-29', geo = 'PE'))

Created on 2018-05-02 by the reprex package (v0.2.0).

@eddelbuettel
Copy link
Collaborator

The & is a special character for web requests. Using 'and' works.

@tokumotion
Copy link

@PMassicotte weird, it fixed itself. Maybe a Google problem?

@arseny-gorbenko
Copy link

I have a similar problem when trying to download searches for "S&P 500" and still cannot find a solution to it.

x1 <- as.data.frame(gtrends(keyword="S&P500", geo = "US", time="2004-01-01 2017-12-31")[1])
Error: widget$status_code == 200 is not TRUE

@tokumotion as I see the problem resolved itself for the second search (c('toyota', 'yaris', 'corolla')).. but what about the first search with the special character ("Bath & body works")?

@eddelbuettel unfortunately, in my case I cannot exchanges & to 'and', because I need to understand how often people searched exactly for "S&P" (i.e. GoogleTrends will give different search results depending on whether you type "S&P", or "SandP", or "S and P", etc.)

@PMassicotte
Copy link
Owner

What about:

gtrends(keyword="S+P500", geo = "US", time="2004-01-01 2017-12-31")

@arseny-gorbenko
Copy link

arseny-gorbenko commented May 23, 2018

No, it doesn't work either: it doesn't give the same results as manually searching "S&P500" in GoogleTrends (not even in the same ballpark: retrieved scores are very different).

I know that GoogleTrends returns the scores from the random subset of the actual historical search data, but if the search terms are identical then they should be in the same ballpark every time I search them in GoogleTrends. E.g. if I search "SP 500" manually in GoogleTrends I get the identical or almost identical results as if I do it in R with the following command:
gtrends(keyword="SP 500", geo = "US", time="2004-01-01 2017-12-31")

PMassicotte added a commit that referenced this issue May 24, 2018
Can now search with keywords containing '&' (closes #267)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants