Twitch Webhook question

Hello, I’m trying to subscribe to the streams_changed topic event using wordpress as a platform. I’m not using the REST API plugin, just vanilla wordpress, however I’m a little confused with this:

Subscription verify — If your subscription request passes review, Twitch sends you a request to confirm that you requested the subscription. To confirm, respond to the request with the challenge token provided ( hub.challenge ) in the query parameters and an HTTP success (2xx) response code. Important Note The challenge token should be echoed back in a simple text/plain response, without any JSON/HTML wrapping.

What should the response actually look like? Wordpress have helper functions like wp_send_json, wp_send_sucess_json, wp_remote_post (which sends a post request, etc.

Twitch sends hub.challenge as a query string argument.

In PHP you grab this with $_GET['hub_challenge'] iirc


if (isset($_GET['hub_challenge'])) {
    echo $_GET['hub_challenge'];

Should suffice for acknowledge in Wordpress. As long as this fires before any template code runs.

Interesting, honestly I’m still a novice when it comes to wordpress and php. I thought echo was just for printing to the screen and didn’t have any relevance when it came to replying to http requests. I’m more versed in node where you’d have a reply object and use that to respond to the request (but obviously that’s within a rest api structure).

To respond to a webhook you just “echo to the screen”

Just only the Twitch server making the request will “see” the screen.

“echo” is basically the same as resp.send('words and stuff'); in node. (Just PHP lets you echo lots of times (until exit; or end of program) where as resp.send will send and end)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.