Я хочу создать бота в твиттере, используя твиттер и API Spotify. Пока что у меня неплохой старт, но теперь я столкнулся с проблемой, которую не могу решить самостоятельно:
Мне нужно знать имя исполнителя и песню из топ-1 50 лучших песен Spotify. Итак, я отправил запрос Spotify API и получил этот ответ json:
{
"href" : "https://api.spotify.com/v1/playlists/37i9dQZEVXbIPWwFssbupI/tracks?offset=0&limit=1",
"items" : [ {
"added_at" : "1970-01-01T00:00:00Z",
"added_by" : {
"external_urls" : {
"spotify" : "https://open.spotify.com/user/"
},
"href" : "https://api.spotify.com/v1/users/",
"id" : "",
"type" : "user",
"uri" : "spotify:user:"
},
"is_local" : false,
"primary_color" : null,
"track" : {
"album" : {
"album_type" : "single",
"artists" : [ {
"external_urls" : {
"spotify" : "https://open.spotify.com/artist/7IlRNXHjoOCgEAWN5qYksg"
},
"href" : "https://api.spotify.com/v1/artists/7IlRNXHjoOCgEAWN5qYksg",
"id" : "7IlRNXHjoOCgEAWN5qYksg",
"name" : "Aya Nakamura",
"type" : "artist",
"uri" : "spotify:artist:7IlRNXHjoOCgEAWN5qYksg"
} ],
"available_markets" : [ "AD", "AE", "AL", "AR", "AT", "AU", "BA", "BE", "BG", "BH", "BO", "BR", "BY", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE",
"DK", "DO", "DZ", "EC", "EE", "EG", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HR", "HU", "ID", "IE", "IL", "IN", "IS", "IT", "JO", "JP", "KW", "KZ", "LB", "LI", "LT", "LU", "LV", "MA", "MC", "MD", "ME", "MK", "MT", "MX", "MY", "NI", "NL", "NO", "NZ", "OM", "PA", "PE", "PH", "PL", "PS", "PT", "PY", "QA", "RO", "RS", "RU", "SA", "SE", "SG", "SI", "SK", "SV", "TH", "TN", "TR", "TW", "UA", "US", "UY", "VN", "XK", "ZA" ],
"external_urls" : {
"spotify" : "https://open.spotify.com/album/43sqDUJkvHHK0ikoAN4JAS"
},
"href" : "https://api.spotify.com/v1/albums/43sqDUJkvHHK0ikoAN4JAS",
"id" : "43sqDUJkvHHK0ikoAN4JAS",
"images" : [ {
"height" : 640,
"url" : "https://i.scdn.co/image/ab67616d0000b273e2e7c5322770c06bdfead61f",
"width" : 640
}, {
"height" : 300,
"url" : "https://i.scdn.co/image/ab67616d00001e02e2e7c5322770c06bdfead61f",
"width" : 300
}, {
"height" : 64,
"url" : "https://i.scdn.co/image/ab67616d00004851e2e7c5322770c06bdfead61f",
"width" : 64
} ],
"name" : "Jolie nana",
"release_date" : "2020-07-17",
"release_date_precision" : "day",
"total_tracks" : 1,
"type" : "album",
"uri" : "spotify:album:43sqDUJkvHHK0ikoAN4JAS"
},
"artists" : [ {
"external_urls" : {
"spotify" : "https://open.spotify.com/artist/7IlRNXHjoOCgEAWN5qYksg"
},
"href" : "https://api.spotify.com/v1/artists/7IlRNXHjoOCgEAWN5qYksg",
"id" : "7IlRNXHjoOCgEAWN5qYksg",
"name" : "Aya Nakamura",
"type" : "artist",
"uri" : "spotify:artist:7IlRNXHjoOCgEAWN5qYksg"
} ],
"available_markets" : [ "AD", "AE", "AL", "AR", "AT", "AU", "BA", "BE", "BG", "BH", "BO", "BR", "BY", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "DZ", "EC", "EE", "EG", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HR", "HU", "ID", "IE", "IL", "IN", "IS", "IT", "JO", "JP", "KW", "KZ", "LB", "LI", "LT", "LU", "LV", "MA", "MC", "MD", "ME", "MK", "MT", "MX", "MY", "NI", "NL", "NO", "NZ", "OM", "PA", "PE", "PH", "PL", "PS", "PT", "PY", "QA", "RO",
"RS", "RU", "SA", "SE", "SG", "SI", "SK", "SV", "TH", "TN", "TR", "TW", "UA", "US", "UY", "VN", "XK", "ZA" ],
"disc_number" : 1,
"duration_ms" : 147076,
"episode" : false,
"explicit" : false,
"external_ids" : {
"isrc" : "FRZ042000666"
},
"external_urls" : {
"spotify" : "https://open.spotify.com/track/34FbkFgAbv4ffvhL2XQMVm"
},
"href" : "https://api.spotify.com/v1/tracks/34FbkFgAbv4ffvhL2XQMVm",
"id" : "34FbkFgAbv4ffvhL2XQMVm",
"is_local" : false,
"name" : "Jolie nana",
"popularity" : 83,
"preview_url" : "https://p.scdn.co/mp3-preview/f38309ea40d6b20b4a7a6b72209b503342b1b147?cid=8f22024a4f144cd7b965b9db6e124e94",
"track" : true,
"track_number" : 1,
"type" : "track",
"uri" : "spotify:track:34FbkFgAbv4ffvhL2XQMVm"
},
"video_thumbnail" : {
"url" : null
}
} ],
"limit" : 1,
"next" : "https://api.spotify.com/v1/playlists/37i9dQZEVXbIPWwFssbupI/tracks?offset=1&limit=1",
"offset" : 0,
"previous" : null,
"total" : 50
}
Я поместил этот ответ в переменную myJSON
и хочу создать переменную, содержащую только Aya Nakamura
и другой, содержащий только Jolie Nana
. Я уже пытался получить данные, используя myJSON.items
и myJSON[items]
, но обе эти строки возвращают undefined
Надеюсь, я объяснил это хорошо.
Спасибо за помощь, и, пожалуйста, извините меня за мой английский sh, так как я говорю по-французски.