Php for retrieve list a video archived

  1. Don’t use file_get_contents
  2. Don’t use file_get_contents
  3. Don’t use file_get_contents
  4. Don’t use file_get_contents
  5. Don’t use file_get_contents
  6. Don’t use file_get_contents
  7. Don’t use file_get_contents
  8. Don’t use file_get_contents
  9. Don’t use file_get_contents
  10. 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