- Don’t use file_get_contents
- Don’t use file_get_contents
- Don’t use file_get_contents
- Don’t use file_get_contents
- Don’t use file_get_contents
- Don’t use file_get_contents
- Don’t use file_get_contents
- Don’t use file_get_contents
- Don’t use file_get_contents
- Don’t use file_get_contents
Did I mention, don’t use file_get_contents!
You need to conver to using cURL
Try
<?php
$ch = curl_init('https://api.twitch.tv/helix/videos?user_id=' . $user_id);
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);
curl_close($ch);
if ($i['http_code'] == 200) {
$videos = json_decode($r);
if (json_last_error() == JSON_ERROR_NONE) {
// do stuff with $videos
} else {
$error = 'An Error ocucred at Parsing the vidoes response';
}
} else {
$error = 'An Error occured fetching the vidoes';
}
Also, don’t use file_get_contents