console.log( "client_credentials",
"client_id" => $clientId,
"client_secret" => $clientSecret
]));
$response = curl_exec($ch);
$response = json_decode($response, true);
$accessToken = $response["access_token"];
// Use the access token to get the top 10 songs for the given country
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.spotify.com/v1/playlists/37i9dQZEVXbMDoHDwVN2tF/tracks?country=$country&limit=10");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $accessToken"
]);
$response = curl_exec($ch);
$response = json_decode($response, true);
$tracks = $response["items"];
// Print the top 10 songs
echo "Top 10 played songs in $country:\n";
foreach ($tracks as $track) {
echo $track["track"]["name"] . " by " . $track["track"]["artists"][0]["name"] . "\n";
});