Skip to content

Instantly share code, notes, and snippets.

@joehari9
Forked from ahallora/getSpotifyAccessToken
Created October 9, 2021 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joehari9/f6c7cc0073d700846c3aeea7d5d8be6f to your computer and use it in GitHub Desktop.
Save joehari9/f6c7cc0073d700846c3aeea7d5d8be6f 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