It’s not actually functional, I just took the bare-minimum from the class I wrote for it.
<?php
define("CHANNEL_NAME", "se7ensinslivestream");
define("OAUTH_TOKEN", "removed");
$response = set_channel_info($channel_status, $channel_game);
public function set_channel_info($status = null, $game = null, $delay = 0)
{
$params = array("channel" => array());
if(!is_null($status))
{
$params["channel"]["status"] = $status;
}
if(!is_null($game))
{
$params["channel"]["game"] = $game;
}
if(is_int($delay) && $delay > 0)
{
$params["channel"]["delay"] = $delay;
}
return twitch_api_request("channels/" . CHANNEL_NAME, $params, "PUT");
}
function twitch_api_request($command = null, $params = null, $method = "GET", $add_oauth = true, $is_json = true)
{
$ch = curl_init();
if(is_null($command))
{
curl_setopt($ch, CURLOPT_URL, API_URL);
}
else
{
curl_setopt($ch, CURLOPT_URL, API_URL . $command);
}
switch($method)
{
case "POST":
curl_setopt($ch, CURLOPT_POST, true); break;
case "PUT":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); break;
case "DELETE":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); break;
default:
break;
}
$headers = array("Accept: application/vnd.twitchtv.v" . API_VERSION . "+json");
if($add_oauth)
{
$headers[] = "Authorization: OAuth " . OAUTH_TOKEN;
}
if(!is_null($params))
{
if($is_json)
{
$params = json_encode($params);
$headers[] = "Content-Type: application/json";
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
}
curl_setopt_array($ch, array(
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true
));
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
return $response;
}
?>