Before starting with the code, to use OAuth an application has to be registered with Spotify. This is done using the developer portal:
https://developer.spotify.com/my-applications/#!/applications
An application must be created to acquire a Client ID and Client Secret. The following screenshot is of a temporary application created for this process:
The values from the web page will fill three variables:
$clientId = 'FromSpotify' $clientSecret = 'FromSpotify' $redirectUrl = 'AnyURL'