【问题标题】:R - Multiple artists Spotify API functionR - 多位艺术家 Spotify API 功能
【发布时间】:2018-05-03 19:59:17
【问题描述】:

为新手问题道歉,但我正在努力解决以下问题;

我正在使用 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,以检索歌曲的声学元素。

非常感谢您的帮助(希望/可能相当容易?;-))

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

【问题讨论】:

  • 您是否尝试过对列表进行循环或迭代?
  • 我还没有,老实说,我对这些(还)不太熟悉。你愿意分享一个例子吗? :)

标签: r list spotify


【解决方案1】:

这是一种使用 {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))

【讨论】:

  • 另一个问题,然后我得到了一切!当您只需要使用一个列表而不是用户名和 ID 来检索结果时,上面提到的行会是什么样子?我尝试使用上面的示例并将其修改为此功能,但失败了。 artist_info &lt;- getArtistinfo("0X6CDvMiFMeLxVnKUq9oWy", token = keys) 收到以下错误:Error in as_mapper(.f, ...) : argument ".f" is missing, with no default 谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-27
  • 1970-01-01
  • 2018-05-11
相关资源
最近更新 更多