# API twitch update ? get viewers?

**URL:** <https://discuss.dev.twitch.com/t/api-twitch-update-get-viewers/7473>\
**Category:** API\
**Created:** [September 17, 2016, 10:44pm UTC](https://discuss.dev.twitch.com/t/api-twitch-update-get-viewers/7473 "2016-09-17T22:44:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Toutoupou](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@Toutoupou](https://discuss.dev.twitch.com/u/Toutoupou)\
**Post date:** [September 17, 2016, 10:44pm UTC](https://discuss.dev.twitch.com/t/api-twitch-update-get-viewers/7473/1 "2016-09-17T22:44:11Z")

</div>

hi, i just saw the maj of API twitch. So now we need ID client in url but i’ve got a problem to get viewers of one channel.

$.getJSON(‘[https://api.twitch.tv/kraken/streams?client\_id=code&channel=streamer](https://api.twitch.tv/kraken/streams?client_id=code&channel=streamer)’, function(channel) {

channel[“streams”][“viewers”];

}

Before the maj, i’ve got no problem to get viewers but now it doesn’t work… (undefined viewers)

Thanks !

---

<div class="post-metadata">

**Author:** ![lowbob17](https://avatars.discourse-cdn.com/v4/letter/l/f07891/32.png) [@lowbob17](https://discuss.dev.twitch.com/u/lowbob17)\
**Post date:** [September 18, 2016, 11:34am UTC](https://discuss.dev.twitch.com/t/api-twitch-update-get-viewers/7473/2 "2016-09-18T11:34:14Z")

</div>

In PHP i can show the Viewers with that Code:

> $url = “[https://api.twitch.tv/kraken/streams/streamer?client\_id=$client\_id](https://api.twitch.tv/kraken/streams/streamer?client_id=$client_id)”;

> $result = file\_get\_contents($url);  
> $result = json\_decode($result, true);

> $result[“stream”][“viewers”]

May it help…

---

<div class="post-metadata">

**Author:** ![george](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/george/32/120_2.png) [@george](https://discuss.dev.twitch.com/u/george)\
**Post date:** [September 18, 2016, 1:48pm UTC](https://discuss.dev.twitch.com/t/api-twitch-update-get-viewers/7473/3 "2016-09-18T13:48:25Z")

</div>

If you are only querying a single channel you want to use `https://api.twitch.tv/kraken/streams/CHANNELNAME?client_id=code` instead and your code would work.

/streams by itself will return an array of stream objects so you would need to access them index (`channel["streams"][0..n]["viewers"]`) or iterate over the streams array in the result.

---

<div class="post-metadata">

**Author:** ![Toutoupou](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@Toutoupou](https://discuss.dev.twitch.com/u/Toutoupou)\
**Post date:** [September 18, 2016, 2:18pm UTC](https://discuss.dev.twitch.com/t/api-twitch-update-get-viewers/7473/4 "2016-09-18T14:18:39Z")

</div>

ah ok ! thanks a lot it’s work now !

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [October 18, 2016, 2:18pm UTC](https://discuss.dev.twitch.com/t/api-twitch-update-get-viewers/7473/5 "2016-10-18T14:18:46Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
