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

Error in parse_url(url) : length(url) == 1 is not TRUE #196

Open
eledroos opened this issue Mar 25, 2023 · 4 comments
Open

Error in parse_url(url) : length(url) == 1 is not TRUE #196

eledroos opened this issue Mar 25, 2023 · 4 comments

Comments

@eledroos
Copy link

I know this has been posted before #73 (comment)

Steps to reproduce:

id <- ''
secret <- ''
Sys.setenv(SPOTIFY_CLIENT_ID = id)
Sys.setenv(SPOTIFY_CLIENT_SECRET = secret)
access_token <- get_spotify_access_token()

my_id <- 'ID'
my_plists <- get_user_playlists(my_id)

my_plists2 <- my_plists %>%
  filter(id %in% c('PLAYLIST_ID'))

tracks <- get_playlist_tracks(my_plists2)

Fails on the get_playlist_tracks() function. Other features of spotifyr work fine, that work fails. Can't tell why. Any clue?

@eledroos
Copy link
Author

eledroos commented Apr 3, 2023

Did some investigation.

Inside get_playlist_tracks() the error message suggests that the url argument being passed to parse_url() has a length that is not equal to 1. Google says that this could happen if url is a vector or a list instead of a single string.

So I printed the value of url and it seems the function is not properly filtering out invalid playlist IDs from the my_plists2 vector.

I passed it the value of the playlist ID on it's own (instead of my_plists2), taken directly from my_plists, and it seems to have worked fine. Going to investigate more.

@eledroos
Copy link
Author

eledroos commented Apr 3, 2023

Well. Even though I can get the tracks, I cannot get the features as features <- get_track_audio_features(tracks) provides the following error:

> features <- get_track_audio_features(tracks)
Error in curl::curl_fetch_memory(url, handle = handle): Connection died, tried 5 times before giving up
Request failed [ERROR]. Retrying in 1 seconds...
Error in curl::curl_fetch_memory(url, handle = handle): Connection died, tried 5 times before giving up
Request failed [ERROR]. Retrying in 2.9 seconds...
Error in curl::curl_fetch_memory(url, handle = handle) : 
  Connection died, tried 5 times before giving up

It's not a connection issue as far as I can tell, as re-running the previous line of code to get the tracks again, immediately after the error, is fine.

EDIT after some more diagnosing, the issue seems to be related to the format of the input ids parameter. The get_track_audio_features() function is expecting a vector of track IDs I think, where each ID is a string of characters.

Running the code as follows returns the audio features correctly:

track_ids <- tracks$track.id
features <- get_track_audio_features(track_ids)

@vicmermon
Copy link

vicmermon commented Apr 23, 2024

Hello, I'm trying to make a loop with the 'for' function to get the tracks from a bunch of playlists at once. I'm getting the same error, because i have my playlist Ids saved as a vector. If I put a single string (just one ID by itself) the function works perfectly, but I cannot get it to work with the loop that I need. Do you have any ideas on how can I fix this?

datos_pistas <- data.frame()

for (id in ids_listas) {
  tracksfrom_playlist <- get_playlist_tracks(
    playlist_id = playlist_id,
    fields = NULL,
    offset = 0,
    market = NULL,
    authorization = get_spotify_access_token()
  )
  
  datos_pistas <- rbind(datos_pistas, tracksfrom_playlist)
  
  Sys.sleep(100)
}

@eledroos
Copy link
Author

@vicmermon I'm trying to remember how I fixed this but I'd suggest checking the creation of your vector. Once I looked at url and realized that there was something up with my vector, I think I manually recreated the vector and it worked fine. The issue is somewhere there, as like you've noted you're able to send a single string in to get_playlist_tracks() and it works fine.

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

2 participants