Skip to content

Instantly share code, notes, and snippets.

@thiagoguarnieri
Created March 22, 2016 13:51
Show Gist options
  • Save thiagoguarnieri/6d54e1d78b713eb568a0 to your computer and use it in GitHub Desktop.
Save thiagoguarnieri/6d54e1d78b713eb568a0 to your computer and use it in GitHub Desktop.
Get Spotify Access Token (client credentials) with PHP and cURL
//based on https://gist.github.com/ahallora/4aac6d048742d5de0e65
$client_id = 'your client id';
$client_secret = 'your client secret';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://accounts.spotify.com/api/token');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
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;
@ahallora
Copy link

ahallora commented Dec 8, 2016

Just stumbled upon this gem. Cheers mate 😄 👍

@thiagoguarnieri
Copy link
Author

I am happy to help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment