Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ramarty committed Jan 3, 2025
1 parent 42b3278 commit 8a5cb72
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 43 deletions.
49 changes: 12 additions & 37 deletions R/blackmarbler.R
Original file line number Diff line number Diff line change
Expand Up @@ -528,48 +528,23 @@ download_raster <- function(file_name,

if(quiet == FALSE) message(paste0("Processing: ", file_name))


if(quiet == TRUE){

url1 <<- url
# response <- httr::GET(url,
# httr::timeout(60),
# httr::add_headers(headers),
# httr::write_disk(download_path, overwrite = TRUE))

response <- httr2::request(url) %>%
httr2::req_headers('Authorization' = paste('Bearer', bearer)) %>%
httr2::req_timeout(60) %>%
httr2::req_perform()

writeBin(httr2::resp_body_raw(response), download_path)


} else{

response <- httr2::request(url) %>%
httr2::req_headers('Authorization' = paste('Bearer', bearer)) %>%
httr2::req_timeout(60) %>%
httr2::req_perform()

writeBin(httr2::resp_body_raw(response), download_path)

# response <- httr::GET(url,
# httr::timeout(60),
# httr::add_headers(headers),
# httr::write_disk(download_path, overwrite = TRUE),
# httr::progress())

}
response <- httr2::request(url) %>%
httr2::req_headers('Authorization' = paste('Bearer', bearer)) %>%
httr2::req_timeout(60) %>%
httr2::req_perform()

if(response$status_code != 200){
message("Error in downloading data")
message(response)
stop("Error in downloading data")
}

if(response$status_code == 200){
if(length(response$body) < 10000){
stop(paste0("Issue with bearer token. You may need to generate a new token. Ensure that select EULAs are accepted. Please see the instructions here: https://github.com/worldbank/blackmarbler?tab=readme-ov-file#bearer-token-"))
}
}

#if(response$all_headers[[1]]$status != 200){
# message("**Error in downloading data; bearer token likely invalid.** Try regenerating the bearer token; please see this link for instructions to obtain a bearer token: https://github.com/worldbank/blackmarbler?tab=readme-ov-file#bearer-token-")
#}
writeBin(httr2::resp_body_raw(response), download_path)

}

Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ Follow the below steps to obtain a bearer token:

1. Create a [NASA Earth Data account](https://ladsweb.modaps.eosdis.nasa.gov/) account. On the top right, click "Login" then "Earthdata Login". Then click "register" (blue button).
2. Enter the information in the registration page. You __must__ include the following information; this information is not required to create an account, but the bearer token will not work without this information:
- Study Area
- User Type
- Organization

- Study Area
- User Type
- Organization

3. Click "Register for EarthData Login" (green button at bottom). Check your email, and click the link in the email to activate the account.
4. Go to the [Earth Data Login](https://urs.earthdata.nasa.gov/users) page and login.
5. On the panel near the top, click "EULAs" then "Accept New EULAs". Accept:
- MERIS EULA
- Sentinel EULA

- MERIS EULA
- Sentinel EULA

6. On the "Profile Home" page, you should see something like below. Information should be filled in for each category, and "Agreed To Meris EULA" and "Agreed To Sentinel-3 EULA" should be True.

Expand All @@ -77,7 +79,7 @@ Follow the below steps to obtain a bearer token:

### Programmatically retrieve token <a name="token-automatic">

After following the above steps, the bearer token can be programmatically retrieved using the `get_nasa_token()` function and your usename and password.
After following the above steps, the bearer token can also be programmatically retrieved using the `get_nasa_token()` function and your usename and password.

```r
bearer <- get_nasa_token(username = "USERNAME-HERE",
Expand Down

0 comments on commit 8a5cb72

Please sign in to comment.