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

Fix for getAlbums: HTTP error 401 #11

Open
bbrewington opened this issue Jul 15, 2017 · 0 comments
Open

Fix for getAlbums: HTTP error 401 #11

bbrewington opened this issue Jul 15, 2017 · 0 comments

Comments

@bbrewington
Copy link
Contributor

I'm getting "Error in open.connection(con, "rb") : HTTP error 401." when I run the following:

getAlbums("3z6Gk257P9jNcZbBXJNX5i", type = "album", market = "US")
# this is using the Regina Spektor artist id provided in the readme

Solves a couple issues I found in the getAlbums function:

  1. 401 unauthorized error because no token involved
  2. The string "/albums??&album_type=album" seems to be an invalid URL format
  3. I converted the jsonlite::fromJSON calls to httr::GET to allow for the httr::config(token = token) argument
getAlbums <- function(id, type = "album", market = "US", token)
{
  require(dplyr)
  total <- httr::content(httr::GET(paste0("https://api.spotify.com/v1/artists/", 
                                     id, "/albums?album_type=album"),
                     httr::config(token = token)))$total
  req <- httr::GET(paste0("https://api.spotify.com/v1/artists/", 
                                   id, "/albums?offset=0&limit=", total, "&album_type=", 
                                   type, "&market=", market),
                   httr::config(token = token))
  return(lapply(httr::content(req)$items, 
                function(x) data.frame(
                  id = x$id, 
                  name = x$name, 
                  album_type = x$album_type, 
                  available_markets = paste(x$available_markets, collapse = ", "),
                  stringsAsFactors = F)) %>% 
           bind_rows())
}
@bbrewington bbrewington changed the title getAlbums error Fix for getAlbums: HTTP error 401 Jul 15, 2017
@bbrewington bbrewington mentioned this issue Jul 15, 2017
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

1 participant