tidyverse / googledrive

Google Drive R API
https://googledrive.tidyverse.org/
Other
322 stars 47 forks source link

Allow to parse URL with query string #450

Closed netique closed 9 months ago

netique commented 9 months ago

Not sure if this behavior is deliberate, but as_id() aborts when the URL contains a query string. When I obtain a URL of a directory directly from Google Drive, it is always present, so I have to remove everything after the question mark to get drive_id. In the documentation as_id() is even described as it "...converts various inputs into an instance of drive_id".

Here’s a reprex to be clear:

library(googledrive)

url_to_share <- "https://drive.google.com/drive/folders/1vkD7gqsJ7r3C2FZfS2_48jxjcZIXXaTC?usp=drive_link"
url_edited <- "https://drive.google.com/drive/folders/1vkD7gqsJ7r3C2FZfS2_48jxjcZIXXaTC"

as_id(url_to_share)
#> Error in `validate_drive_id()`:
#> ! A <drive_id> must match this regular expression: `^[a-zA-Z0-9_-]+$`
#> Invalid input:
#> ✖ '1vkD7gqsJ7r3C2FZfS2_48jxjcZIXXaTC?usp=drive_link'
#> Backtrace:
#>     ▆
#>  1. ├─googledrive::as_id(url_to_share)
#>  2. └─googledrive:::as_id.character(url_to_share)
#>  3.   └─googledrive:::validate_drive_id(new_drive_id(out))
#>  4.     └─googledrive:::drive_abort(...)
#>  5.       └─cli::cli_abort(message = message, ..., .envir = .envir)
#>  6.         └─rlang::abort(...)
as_id(url_edited)
#> <drive_id[1]>
#> [1] 1vkD7gqsJ7r3C2FZfS2_48jxjcZIXXaTC

Created on 2023-12-07 with reprex v2.0.2