Я недавно начал изучать Java и загрузку Spring и хотел использовать API Spotify для получения информации об артистах.
Я использовал следующее и получаю ответ
String accessToken = getToken(); // method made to generate token
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Object> retrieveArtistInfo = restTemplate.exchange("https://api.spotify.com/v1/artists"+"?ids="+Arrays.toString(ids).replace("[", "").replace("]", ""), HttpMethod.GET, request, Object.class);
Response:
{
"artists": [
{
"headers": {
"Content-Type": [
"application/json; charset=utf-8"
],
"Cache-Control": [
"public, max-age=72437"
],
"X-Robots-Tag": [
"noindex, nofollow"
],
"Access-Control-Allow-Origin": [
"*"
],
"Access-Control-Allow-Headers": [
"Accept, App-Platform, Authorization, Content-Type, Origin, Retry-After, Spotify-App-Version, X-Cloud-Trace-Context"
],
"Access-Control-Allow-Methods": [
"GET, POST, OPTIONS, PUT, DELETE, PATCH"
],
"Access-Control-Allow-Credentials": [
"true"
],
"Access-Control-Max-Age": [
"604800"
],
"content-length": [
"916"
],
"Date": [
"Mon, 13 Apr 2020 07:42:09 GMT"
],
"Via": [
"1.1 google"
],
"Alt-Svc": [
"clear"
]
},
"body": {
"artists": [
{
"external_urls": {
"spotify": "https://open.spotify.com/artist/4q3ewBCX7sLwd24euuV69X"
},
"followers": {
"href": null,
"total": 20399255
},
"genres": [
"latin",
"reggaeton",
"trap latino"
],
"href": "https://api.spotify.com/v1/artists/4q3ewBCX7sLwd24euuV69X",
"id": "4q3ewBCX7sLwd24euuV69X",
"images": [
{
"height": 640,
"url": "https://i.scdn.co/image/23009960c33ef08d5973440cca17985a6c70a515",
"width": 640
},
{
"height": 320,
"url": "https://i.scdn.co/image/8ff3e392402169f239bce72b3d80c701b75150b8",
"width": 320
},
{
"height": 160,
"url": "https://i.scdn.co/image/624dd15f5bdcc1bae5fa47739601f3e0be62ebda",
"width": 160
}
],
"name": "Bad Bunny",
"popularity": 100,
"type": "artist",
"uri": "spotify:artist:4q3ewBCX7sLwd24euuV69X"
}
]
},
"statusCode": "OK",
"statusCodeValue": 200
}
]
}
Я могу увидеть тело ответа, передавая retrieveArtistInfo.getBody (), но я бы хотел получить такие вещи, как жанры, внешние URL-адреса из объекта, в котором я его хранил, и сделать свой собственный ответ, но я не знаю, go о доступе к этим элементам. У кого-нибудь есть советы, как это можно получить?