Once again I need your help. This is not working, I get “401 missing user information but i have all well setted”. Thanks in advance.
$client_id = 'xxxxxxxxxxxxxxxxx';
$client_secret = 'xxxxxxxxxxxxxxxxxxxxx';
$url = 'https://id.twitch.tv/oauth2/token';
$data = array('client_id' => $client_id, 'client_secret' => $client_secret, 'grant_type' => 'client_credentials');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {}
#var_dump($result);
$arrresult=json_decode($result);
foreach ($arrresult as $key=>$obj){
#echo " $key => $obj <br>";
if ($key="access_token") { $token=$obj; break; }
}
echo "token $token<br><br>";
$user_id=xxxxxxxxxxx;
/*$ch = curl_init('https://api.twitch.tv/helix/streams'); #streams #videos
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Client-ID: ' . $client_id,
'Authorization: Bearer ' . $token
));
$r = curl_exec($ch);
$i = curl_getinfo($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.twitch.tv/helix/channels?broadcaster_id=' . $broadcaster_id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"title\":\"$title\", \"broadcaster_language\":\"es\"}");
$headers = array();
$headers[] = "Authorization: Bearer $token";
$headers[] = "Client-Id: $client_id";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$i = curl_getinfo($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);