1

使用 Apple Music API,我可以在我的库中获取所有艺术家:

func getArtists(forToken musicUserToken: String) {
    var urlComponents = URLComponents()
    urlComponents.scheme = "https"
    urlComponents.host = "api.music.apple.com"
    urlComponents.path = "/v1/me/library/artists"

    var request = URLRequest(url: urlComponents.url!)
    request.setValue("Bearer (developerToken)", forHTTPHeaderField: "Authorization")
    request.setValue(musicUserToken, forHTTPHeaderField: "Music-User-Token")

    let dataTask = URLSession.shared.dataTask(with: request) { (data, urlResponse, error) in
        ...
    }
    dataTask.resume()
}

例如,上面的代码返回这个 JSON:

{
    "data":[
        {
            "attributes":{
                "name":"Anne-Marie"
            },
            "href":"/v1/me/library/artists/r.wb9aRPu",
            "id":"r.wb9aRPu",
            "type":"library-artists"
        },
        {
            "attributes":{
                "name":"Bruno Mars"
            },
            "href":"/v1/me/library/artists/r.zCrRBIw",
            "id":"r.zCrRBIw",
            "type":"library-artists"
        },
        ...
    ]
}

但是,在我看来,每个对象都指的是我图书馆中的艺术家,而不是 Apple Music 图书馆中的艺术家。因为如果我得到艺术家id并尝试得到这个艺术家的专辑,什么都找不到。例如,对 URL 的 GET 会https://api.music.apple.com/v1/catalog/us/artists/r.wb9aRPu返回错误:

{
    "errors":[
        {
            "id":"GJXVG3NROYGJPDRECZLCPYKLEQ",
            "title":"Internal Service Error",
            "status":"500",
            "code":"50000"
        }
    ]
}

但是,如果我对艺术家 ID 178834(我从 Apple 网站上的一个示例中获得)执行相同的 GET,它会返回正确的响应:

{
    "data":[
        {
            "id":"178834",
            "type":"artists",
            "href":"/v1/catalog/us/artists/178834",
            "attributes":{
                "name":"Bruce Springsteen",
                "genreNames":[
                    "Rock"
                ],
                "url":"https://itunes.apple.com/us/artist/bruce-springsteen/178834"
            },
            "relationships":{
                "albums":{
                    "data":[
                        {
                            "id":"1136909069",
                            "type":"albums",
                            "href":"/v1/catalog/us/albums/1136909069"
                        },
                        {
                            "id":"1134170183",
                            "type":"albums",
                            "href":"/v1/catalog/us/albums/1134170183"
                        },
                        ...
                    ],
                    "href":"/v1/catalog/us/artists/178834/albums",
                    "next":"/v1/catalog/us/artists/178834/albums?offset=144"
                }
            }
        }
    ]
}

我想要做的是从用户的图书馆中获取所有艺术家的所有专辑。但我不能用/me/library/artists返回的艺术家 ID 做到这一点。那么,是否有另一种方法可以获取用户在库中的艺术家的艺术家 ID?

4

0 回答 0