# Stream Status New Twitch API Upgrade

**URL:** <https://discuss.dev.twitch.com/t/stream-status-new-twitch-api-upgrade/22907>\
**Category:** Migration\
**Created:** [October 22, 2019, 9:28am UTC](https://discuss.dev.twitch.com/t/stream-status-new-twitch-api-upgrade/22907 "2019-10-22T09:28:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![americandeluxe](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@americandeluxe](https://discuss.dev.twitch.com/u/americandeluxe)\
**Post date:** [October 22, 2019, 9:28am UTC](https://discuss.dev.twitch.com/t/stream-status-new-twitch-api-upgrade/22907/1 "2019-10-22T09:28:00Z")

</div>

Hi Everyone,

some time ago someone gave me a PHP script for my website to display a list of online Twitch channels. Now that script is not working anymore. Unfortunately i have no clue what to change to get it working again.

It would be great if someone can help me out here and tell me what to change for the new Twitch API.

This is what i got:

```
    class TwitchConnector
    {
        public static function getStreamsFromTwitch($stream_list)
        {
            $mycurl = curl_init();  
            $url = "https://api.twitch.tv/kraken/streams?channel=" . $stream_list;
    		$clientId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    		curl_setopt_array($mycurl, array(
        		CURLOPT_HTTPHEADER => array('Client-ID: '. $clientId),
        		CURLOPT_RETURNTRANSFER => true,
        		CURLOPT_URL => $url));
            curl_setopt($mycurl, CURLOPT_URL, $url);
            $web_response = curl_exec($mycurl);
            $response = json_decode($web_response);

            $streams = array();
            if($response != null && !empty($response) && $response->streams != null) {
                foreach ($response->streams as $stream) {
                    $streamObj = new Stream();
                    $streamObj->setViewerCount($stream->viewers);
                    $streamObj->setPreviewImage($stream->preview->medium);
                    $streamObj->setDisplayname($stream->channel->display_name);
                    $streamObj->setGame($stream->channel->game);
                    $streamObj->setCaster($stream->channel->name);
                    $streamObj->setDescription(htmlspecialchars($stream->channel->status));
                    $streams[] = $streamObj;
                }
            }
    		return $streams;
        }
    }

```

There also is a 2nd PHP File, which is providing the `$stream_list`

Thank you very much 🙂

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 22, 2019, 10:18am UTC](https://discuss.dev.twitch.com/t/stream-status-new-twitch-api-upgrade/22907/2 "2019-10-22T10:18:26Z")

</div>

Please refer to the migration guide

[https://dev.twitch.tv/docs/v5/guides/migration](https://dev.twitch.tv/docs/v5/guides/migration)

The following will convert you to V5

```auto
    		curl_setopt_array($mycurl, array(
        		CURLOPT_HTTPHEADER => array('Client-ID: '. $clientId, 'Accept': 'application/vnd.twitchtv.v5+json'),
        		CURLOPT_RETURNTRANSFER => true,
        		CURLOPT_URL => $url));

```

And `$stream_list` needs to be a `user_id` not a `user_name`

Or you can rewrite the script completely to support New API:

> **[Reference](https://dev.twitch.tv/docs/api/reference/)**
>
> Twitch Developer tools and services to integrate Twitch into your development or create interactive experience on twitch.tv.
