console.log( <?php

// Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your own client ID and client secret
$clientId = "YOUR_CLIENT_ID";
$clientSecret = "YOUR_CLIENT_SECRET";

// Get the user's input for the country
echo "Enter the country code (e.g. US, GB, BR): ";
$handle = fopen ("php://stdin","r");
$country = trim(fgets($handle));

// Get an access token from the Spotify API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://accounts.spotify.com/api/token");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
  "grant_type" => "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";
});