Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
?>
@ahallora

This comment has been minimized.

Copy link
Owner Author

ahallora commented Jul 9, 2014

I know it's basic, but I struggled to figure out how to retrieve the access token from the Spotify web service as the only example provided by Spotify was written in node.js. Hopefully this will save you the time and hassle I went through to get this simple script to work. :)

@thiagoguarnieri

This comment has been minimized.

Copy link

thiagoguarnieri commented Mar 21, 2016

Excellent

@Bugs1012

This comment has been minimized.

Copy link

Bugs1012 commented Jun 26, 2016

thanks. i was struggling too.

@tmdevde

This comment has been minimized.

Copy link

tmdevde commented Jun 9, 2017

thank you!

@ludasolo

This comment has been minimized.

Copy link

ludasolo commented Jun 21, 2017

thank you!

@developer-star

This comment has been minimized.

Copy link

developer-star commented Sep 29, 2017

I was very stressful owing to Spotify Oauth.
Many Thanks.
🥇

@alxbastard

This comment has been minimized.

Copy link

alxbastard commented Feb 8, 2018

Thanks, still working. You made my day easier, I was going to use a library for cURL then I found this.

@Mcgurk125

This comment has been minimized.

Copy link

Mcgurk125 commented Jun 13, 2018

Does this still work? - It does not seem to work for me! Can somebody else try?

@MarcoCadei

This comment has been minimized.

Copy link

MarcoCadei commented Jun 22, 2018

Thank you a lot! It worked perfectly for me!

@gustavo9601

This comment has been minimized.

Copy link

gustavo9601 commented Aug 13, 2018

Thank you so much !!!!

@Lucasmg37

This comment has been minimized.

Copy link

Lucasmg37 commented Jul 2, 2019

Nice!

@pablocoronel

This comment has been minimized.

Copy link

pablocoronel commented Jan 23, 2020

Thank you!

@cptstoneee

This comment has been minimized.

Copy link

cptstoneee commented Feb 13, 2020

Thanks much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.