R - 多个艺术家 Spotify API 功能

R - Multiple artists Spotify API function

对于新手问题深表歉意,但我正在努力解决以下问题;

我正在使用 tiagomendesdantas/Rspotify 功能通过 R 访问 Spotify API。当使用它来访问有关单个艺术家、播放列表或曲目的信息时,它工作正常,但我想 运行 这一次适用于多位艺术家。

我试过创建列表等,但没有用。

#Getting the songs of Spotify's RapCaviar playlists
rapcaviar <- getPlaylistSongs(ownerid = "Spotify",
                              "37i9dQZF1DX0XUsuxWHRQd",
                              token = keys) 
rapcaviar

我应该怎么做才能为播放列表或艺术家添加多个 ID?

我经常遇到错误:

Error: length(url) == 1 is not TRUE

理想情况下,您可以将 getartistinfo 函数的结果用于其他选项,例如 getfeatures 来检索歌曲的声学元素。

非常感谢您的帮助(hopefully/probably 相当简单?;-))

Link 函数:https://github.com/tiagomendesdantas/Rspotify/blob/master/DESCRIPTION

这里有一种方法可以使用{purrr}

library(Rspotify)
keys <- spotifyOAuth("rstats","***","***")


library(purrr)
# Create a vector of owners id 
owners_id <- c('11152045841', 'spotify', 'spotify')
# Create a vector of the corresponding playlist id
playlists_id <- c('0FJiPbIDGcxw6hx9dLVQPl', '37i9dQZF1DX5wiMM8SSK44', '37i9dQZF1DWT9SRKhOEUYj')

# Use purrr::map2 to retrieve a list of dataframe of the playlists
playlists <- map2(owners_id, playlists_id, ~ getPlaylistSongs(.x, .y, token = keys))

# You can also use purrr::map2_df if you want to bind if all in a unique data.frame
playlists <- map2_df(owners_id, playlists_id, ~ getPlaylistSongs(.x, .y, token = keys))