Skip to content

Commit

Permalink
Merge pull request #415 from PMassicotte/fix-payload-usertype
Browse files Browse the repository at this point in the history
Fix missing usertype in the payload closes #414).
  • Loading branch information
PMassicotte authored May 23, 2022
2 parents 22d6870 + 683a347 commit 8a2d94a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ URL: https://github.com/PMassicotte/gtrendsR
Depends: R (>= 3.5.0)
LazyData: yes
Imports: ggplot2, jsonlite, anytime, curl
RoxygenNote: 7.1.2
RoxygenNote: 7.2.0
Suggests: knitr, rmarkdown, tinytest
Encoding: UTF-8
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# gtrendsR (development version)

- Fix missing `userType` in the payload which was giving a 401 error (#413).

# gtrendsR 1.5.0

## Bug fixes
Expand Down
1 change: 1 addition & 0 deletions R/related_queries.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ create_related_queries_payload <- function(i, widget, tz, hl) {
payload2$requestOptions$category <- widget$request$requestOptions$category[[i]]
payload2$language <- widget$request$language[[i]]
payload2$userCountryCode <- widget$request$userCountryCode[[i]]
payload2$userConfig$userType <- widget$request$userConfig$userType[[i]]

url <- paste0(
URLencode("https://www.google.com/trends/api/widgetdata/relatedsearches/csv?req="),
Expand Down
1 change: 1 addition & 0 deletions R/related_topics.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ create_related_topics_payload <- function(i, widget, hl, tz) {
widget$request$requestOptions$category[[i]]
payload2$language <- widget$request$language[[i]]
payload2$userCountryCode <- widget$request$userCountryCode[[i]]
payload2$userConfig$userType <- widget$request$userConfig$userType[[i]]

url <- paste0(
URLencode(
Expand Down
3 changes: 3 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ get_widget <- function(comparison_item, category, gprop, hl, cookie_url, tz) {

interest_over_time <- function(widget, comparison_item, tz) {
payload2 <- list()
payload2$userConfig$userType <- widget$request$userConfig$userType[[1]]

# if there is a mix of search and topic terms requests are all shifted by one
# for some reason. Maybe there is a better fix for this. I don't understand
# precisely the structure of the widget.
Expand Down Expand Up @@ -463,6 +465,7 @@ create_geo_payload <- function(i, widget, resolution, compared_breakdown, low_se
payload2$requestOptions$backend <- widget$request$requestOptions$backend[i]
payload2$requestOptions$property <- widget$request$requestOptions$property[i]
payload2$requestOptions$category <- widget$request$requestOptions$category[i]
payload2$userConfig$userType <- widget$request$userConfig$userType[[i]]
payload2$geo <- as.list((widget$request$geo[i, , drop = FALSE]))
payload2$includeLowSearchVolumeGeos <- low_search_volume

Expand Down
1 change: 1 addition & 0 deletions gtrendsr.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ RnwWeave: Sweave
LaTeX: pdfLaTeX

BuildType: Package
PackageCleanBeforeInstall: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd

0 comments on commit 8a2d94a

Please sign in to comment.