r-lib / gargle

Infrastructure for calling Google APIs from R, including auth
https://gargle.r-lib.org/
Other
113 stars 33 forks source link

Bad Request (HTTP 400) with Service Account #287

Closed cfisher5 closed 1 month ago

cfisher5 commented 1 month ago

Over the last several days my scripts that pull data from googlesheets have broken and I have traced the issue to this:

token = gargle::credentials_service_account(path='Googlesheet Auth.json')
Error in init_oauth_service_account(self$secrets, scope = self$params$scope,  :
  Bad Request (HTTP 400).

Googlesheet Auth.json is the path to the service account I've been using for a long time, and this issue is only happening on a windows 2016 server. This exact line of code is working for me on my macbook locally.

sessionInfo() gives me the following:

R version 4.4.1 (2024-06-14 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows Server 2016 x64 (build 14393)

Matrix products: default

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

time zone: America/Chicago
tzcode source: internal

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

other attached packages:
[1] gargle_1.5.2        googledrive_2.1.1   jsonlite_1.8.9
[4] googlesheets4_1.1.1

loaded via a namespace (and not attached):
 [1] crayon_1.5.3     vctrs_0.6.5      httr_1.4.7       cli_3.6.3
 [5] rlang_1.1.4      purrr_1.0.2      promises_1.3.0   generics_0.1.3
 [9] glue_1.7.0       openssl_2.2.2    askpass_1.2.0    httpuv_1.6.15
[13] fansi_1.0.6      rappdirs_0.3.3   cellranger_1.1.0 tibble_3.2.1
[17] lifecycle_1.0.4  compiler_4.4.1   dplyr_1.1.4      fs_1.6.4
[21] Rcpp_1.0.13      pkgconfig_2.0.3  later_1.3.2      R6_2.5.1
[25] tidyselect_1.2.1 utf8_1.2.4       pillar_1.9.0     curl_5.2.3
[29] magrittr_2.0.3   tools_4.4.1

I am hoping someone has a few things to try! I appreciate it in advance. I love these packages and hope i can figure this out, but this issue has really stumped me.

jennybc commented 1 month ago

This sounds a bit like #111 which ended up being a time zone / clock skew issue. That thread also raises the possibility of using httr::with_verbose() to see exactly what's going over the wire.

For more general purpose troubleshooting techniques, see this article:

https://gargle.r-lib.org/articles/troubleshooting.html

cfisher5 commented 1 month ago

clock was somehow 11 minutes into the future. Thanks @jennybc that was a life saver. Who knows how much longer I could have spent on this!