I made some minor changes to your code… and this worked fine for me.
<?php
define("CHANNEL_NAME", "{YOUR_CHANNEL_NAME}");
define("OAUTH_TOKEN", "{YOUR_OAUTH_TOKEN}");
define("API_URL", "https://api.twitch.tv/kraken/");
define("API_VERSION", "3");
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();
curl_setopt($ch, CURLOPT_VERBOSE, true); // if TRUE to output verbose information. Writes output to STDERR, or the file specified using CURLOPT_STDERR.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // don't check certificate
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;
}
$response = set_channel_info("twitch n chill?", "Twitch API");
var_dump($response);