使用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音乐库中的艺术家。因为如果我得到艺术家id
并尝试获取此艺术家专辑,则无法找到任何内容。例如,对URL https://api.music.apple.com/v1/catalog/us/artists/r.wb9aRPu
的GET返回错误:
{
"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?