Skip to content

Instantly share code, notes, and snippets.

@Hadryan
Forked from ahallora/getSpotifyAccessToken
Created March 21, 2022 12:22
Show Gist options
  • Save Hadryan/1f5a0258415d9ccd92c795ecebab7b3e to your computer and use it in GitHub Desktop.
Save Hadryan/1f5a0258415d9ccd92c795ecebab7b3e to your computer and use it in GitHub Desktop.
Get Spotify Access Token (client credentials) with PHP and cURL
<?php
$client_id = '<insert your spotify app client id>';
$client_secret = '<insert your spotify app client secret>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://accounts.spotify.com/api/token' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials' );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic '.base64_encode($client_id.':'.$client_secret)));
$result=curl_exec($ch);
echo $result;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment