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("**************");
Serial.println("What I'm playing right now?");
// Wait 60 seconds
delay(60000);
}
void myHandler(const char *event, const char *data) {
// Handle the integration response
Serial.println("**************");
Serial.println(data);
Serial.println("**************");
}
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 . 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?
I couldn’t find something better there, besides that there are a more people unhappy with the present token (swap) procedure . 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).