Webhook towards Spotify Web API possible?

I’d like to display the currently playing song of my Spotify account on a Photon connected display. The Spotify Web API offers a nice function for this:

Does anyone know if and how it is possible to convert the shown cURL string into a webhook and/or a single URL line?

Thanks in advance!

@RobP Certainly it’s possible!

curl -X GET "https://api.spotify.com/v1/me/player/currently-playing" -H "Accept: application/json" -H "Authorization: Bearer BQDvZYWs7jjnZ5SPUTYo_xTIZrOU3TIG....-0izCc4Qe3__KcTjldyUBOM2R0"

Just make a new Webhook and set it to use GET rather than the default POST. Next, scroll down to the “HTTP HEADERS” section. Split up the two bits that come after “-H” so that you fill “Accept” into the first and then “application/json” into the second. Add another row and do the same for “Authorization” and the token you got from the Spotify site. That should do it.

Next you’ll need to grab the text from your photon like this:

void setup() {
  // Subscribe to the integration response event
  Particle.subscribe("spotifyResponse", myHandler, MY_DEVICES);

void loop() {
  // Get some data
  String data = String(10);
  // Trigger the integration
  Particle.publish("Spotify", data, PRIVATE);
  Serial.println("What I'm playing right now?");
  // Wait 60 seconds

void myHandler(const char *event, const char *data) {
  // Handle the integration response

Here’s how my Webhook looked in the end:

Here’s the template (since it’s not really visible in the screenshot):


That works awesome, thank you @jenschr !

One could also parse for the remaining track length and synchronise the next webhook-publish command based on the song duration. I got a nice demo running, but…

…unfortunately the token is only valid for 60 minutes :sob:. Initially I requested the Oauth token in the browser spotify developer IDE (being logged-in) and used this token in the webhook lateron. I fear it is not possible to implement this complex flow for a refresh token with a Photon alone… right?

Heh… Just a single hour? Didn’t notice that. Pretty sure there’s a way to get a longer lasting token though. I’d dig around on Spotify-related forums?

I couldn’t find something better there, besides that there are a more people unhappy with the present token (swap) procedure :stuck_out_tongue:. Maybe, this service could be a feasable direction?

However I think this extends my current abilities. If someone feels motivated and could find a working solution for the Photon I’d be happy to spend one micro ePaper shield for Particle as a thank you (since I am looking for more connected, ePaper-based reference/demo projects).