I assume I’m missing something obvious, but this code returns:
401
{“error”:“Unauthorized”,“status”:401,“message”:“Must provide a valid Client-ID or OAuth token”}
I can make it so that I’m not sending it as json but I thought that was the problem before because I would get the 202 response, but my notifications handler page would never get any notification with a challenge or denied request.
Any help would be appreciated as I’ve been at this for a while with no progress to show for it… haha
$client_id = “<>”;
$mode = “subscribe”;
$callback_url = “<<my website’s url>>/twitch_notifications_handler”;
$target_user_id = “132154945”;
$lease_days = “10”;
$lease_seconds = $lease_days * 24 * 60 * 60;
$subscribe_to_event_url = “https://api.twitch.tv/helix/webhooks/hub”;
$data = array(
‘hub.mode’ => $mode,
‘hub.topic’ => “https://api.twitch.tv/helix/streams?user_id=”.$target_user_id,
‘hub.callback’ => $callback_url,
‘hub.lease_seconds’ => $lease_seconds
);
$data_string = json_encode($data);
$ch = curl_init($subscribe_to_event_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
'Content-Length: ’ . strlen($data_string)),
'Client-ID: '.$client_id
);
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $httpcode."
".$result;