首页 > 解决方案 > 使用 spotifyr 从 Spotify Top Charts 获取数据

问题描述

我正在尝试使用 R 上的 spotifyr 包获取 2017 年所有前 200 名图表的音频功能,我尝试过:

days<- spotifycharts::chartdaily()
for (i in days) {
    spotifycharts::chart_top200_daily(region = "global",days = "days[i]")
  }

获得 2017 年全年的每日前 200 名,但我无法做到。有人能帮我吗?:(

标签: rloopsspotify

解决方案


It works, if you turn days from tibble into vector:

days <- unlist(chart_daily())

lapply(days[1:3], function(i) chart_top200_daily("global", days = i))

But it parse data badly, so there will be problems with variable names, etc:

# A tibble: 6 x 5
     x1 x2                 x3      note.that.these.figures.are.generated.… x5                 
  <int> <chr>              <chr>                                     <int> <chr>              
1    NA Track Name         Artist                                       NA URL                
2     1 thank u, next      Ariana…                                 8293841 https://open.spoti…
3     2 Taki Taki (with S… DJ Sna…                                 5467625 https://open.spoti…
4     3 MIA (feat. Drake)  Bad Bu…                                 3955367 https://open.spoti…
5     4 Happier            Marshm…                                 3357435 https://open.spoti…
6     5 BAD                XXXTEN…                                 3131745 https://open.spoti…

推荐阅读