# Twitch API Bugged...?

**URL:** <https://discuss.dev.twitch.com/t/twitch-api-bugged/2073>\
**Category:** API\
**Created:** [April 20, 2015, 8:01pm UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073 "2015-04-20T20:01:05Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![ManaPot](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/manapot/32/440_2.png) [@ManaPot](https://discuss.dev.twitch.com/u/ManaPot)\
**Post date:** [April 20, 2015, 8:01pm UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/1 "2015-04-20T20:01:05Z")

</div>

2 days ago I started noticing this problem, where the API will return **really** random stats for a channel. This has been screwing with my site, and it’s becoming a pain in the ass…

[http://i.imgur.com](http://i.imgur.com) X6MbaD4.png (put a slash before the X, I can’t put image links)

https://player.twitch.tv/?channel=Th3Unkn0wnGam3r&autoplay=false

Here is an example. The image is a screenshot of how they look in our database at the moment. Take a look at their Twitch page. First off, the haven’t ever streamed (so why does it say they were playing HearthStone). They have 0 views, and 0 followers…

The viewers, followers and views are all taken directly from the Twitch API and stored in our database. So the numbers shown are a direct result of what Twitch’s API has returned (or so I’m guessing, since there is nothing in between the API call and the database save).

Again, this only started happening 2 days ago. I’ve had this happen to about 20 different streams so far, and I can’t find anything linking them to each other (a reason as to why this is happening). Not all streams are like this, just a few random ones.

[http://www.manabot.tv/streamers/](http://www.manabot.tv/streamers/)

You can view this page to see some streamers, and the screwed up stats (page constantly changing, so it may or may not display a bugged stream).

- I have not changed any code on my end that would cause this issue.

- There is nothing between the API call and the MySQL update query that would alter the information.

- Does not appear to be any correlation between the bugged streams (as far as I can tell).

- Started happening 2 days ago (Friday night).

- The above is just an example. It does this for channels that have and haven’t streamed before, whether they are live or offline.

---

<div class="post-metadata">

**Author:** ![Fugiman](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/fugiman/32/108_2.png) [@Fugiman](https://discuss.dev.twitch.com/u/Fugiman)\
**Post date:** [April 21, 2015, 12:50am UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/2 "2015-04-21T00:50:39Z")

</div>

Please share what api call you’re making to help debug this further.

---

<div class="post-metadata">

**Author:** ![ManaPot](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/manapot/32/440_2.png) [@ManaPot](https://discuss.dev.twitch.com/u/ManaPot)\
**Post date:** [April 21, 2015, 5:11pm UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/3 "2015-04-21T17:11:19Z")

</div>

[https://api.twitch.tv/kraken/streams?channel=[NAME]](https://api.twitch.tv/kraken/streams?channel=%5BNAME%5D)

(With the streamer’s name at the end)

---

<div class="post-metadata">

**Author:** ![jwmalara](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/jwmalara/32/904_2.png) [@jwmalara](https://discuss.dev.twitch.com/u/jwmalara)\
**Post date:** [April 22, 2015, 10:02pm UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/4 "2015-04-22T22:02:22Z")

</div>

Same issue for me: [Inaccurate followers/views values from streams endpoint](https://discuss.dev.twitch.tv/t/inaccurate-followers-views-values-from-streams-endpoint/2093)

---

<div class="post-metadata">

**Author:** ![ManaPot](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/manapot/32/440_2.png) [@ManaPot](https://discuss.dev.twitch.com/u/ManaPot)\
**Post date:** [April 24, 2015, 6:17pm UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/5 "2015-04-24T18:17:12Z")

</div>

[http://i.imgur.com/](http://i.imgur.com/) TddTnT3.png

Still doing it, fairly annoying.

---

<div class="post-metadata">

**Author:** ![Fugiman](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/fugiman/32/108_2.png) [@Fugiman](https://discuss.dev.twitch.com/u/Fugiman)\
**Post date:** [April 26, 2015, 7:52am UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/6 "2015-04-26T07:52:33Z")

</div>

All of those streams have the same views & followers data? That seems suspiciously like a bug in your application code. Is it open source so I can take a peek?

I haven’t seen any indication that our API is reporting terribly wrong numbers on a consistent basis. Occassionally we’ll have blips where we report 0 views/followers, or serve stale data, but that’s very rare and shouldn’t be happening on such a widespread basis.

---

<div class="post-metadata">

**Author:** ![ManaPot](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/manapot/32/440_2.png) [@ManaPot](https://discuss.dev.twitch.com/u/ManaPot)\
**Post date:** [April 26, 2015, 8:55am UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/7 "2015-04-26T08:55:22Z")

</div>

[http://pastebin.com/FiYnXXiA](http://pastebin.com/FiYnXXiA)

- It grabs the API information of the streamer.
- It decodes the JSON.
- Will check if viewer count is set, if not, it will set it to 0.
- Updates the database with the viewer count.

There is a bit more code, I just removed a lot of it (same thing, dif values). As you can see though, I don’t ever edit the value.

---

<div class="post-metadata">

**Author:** ![Fugiman](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/fugiman/32/108_2.png) [@Fugiman](https://discuss.dev.twitch.com/u/Fugiman)\
**Post date:** [April 26, 2015, 1:37pm UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/8 "2015-04-26T13:37:40Z")

</div>

You currently have a few streams marked as “live” on your site that aren’t live. All of their data matches the current top stream - Riotgames. This, plus the code you shared, makes me think that in some cases `$stream_info['name']` is blank, causing your query to our API to return not one stream object, but all available streams. Then you blindly grab the top stream and run your update query that blindly the database… potentially hitting every row since you don’t escape your variables?

If I had unredacted code I could MAYBE try to guess at the bug, but I’ve very confident that the issue is either in how you’re calling our API, how you’re updating the database, or both. Possible values of `$stream_info['name']` would also help.

---

<div class="post-metadata">

**Author:** ![ManaPot](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/manapot/32/440_2.png) [@ManaPot](https://discuss.dev.twitch.com/u/ManaPot)\
**Post date:** [April 26, 2015, 9:23pm UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/9 "2015-04-26T21:23:14Z")

</div>

Hmmm, not sure how that’s possible. I’ll add some debug stuff tonight and let you know what I find.

---

<div class="post-metadata">

**Author:** ![ManaPot](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/manapot/32/440_2.png) [@ManaPot](https://discuss.dev.twitch.com/u/ManaPot)\
**Post date:** [April 26, 2015, 9:28pm UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/10 "2015-04-26T21:28:13Z")

</div>

Also, here is the full script of that function if you want to look it over.

[http://pastebin.com/x94HeLSi](http://pastebin.com/x94HeLSi)

---

<div class="post-metadata">

**Author:** ![jwmalara](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/jwmalara/32/904_2.png) [@jwmalara](https://discuss.dev.twitch.com/u/jwmalara)\
**Post date:** [April 26, 2015, 10:32pm UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/11 "2015-04-26T22:32:06Z")

</div>

Did you see my reply above? [Inaccurate followers/views values from streams endpoint - API - Twitch Developer Forums](http://discuss.dev.twitch.tv/t/inaccurate-followers-views-values-from-streams-endpoint/2093)

The data in in the growth trend is a snapshot of the channel at midnight PST.

Here is a log of what I saw during LIRIKs issue on my post

 ![](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/0855b87497edaff3193c79a0e05615c53ff23910.png)  
There looks like there was another bad data point last night  
 ![](https://d2opxh93rbxzdn.cloudfront.net/original/2X/c/c424cf1246d37bea2645e3f845593b2c8a0e20f5.png)

---

<div class="post-metadata">

**Author:** ![jwmalara](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/jwmalara/32/904_2.png) [@jwmalara](https://discuss.dev.twitch.com/u/jwmalara)\
**Post date:** [April 27, 2015, 7:10pm UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/12 "2015-04-27T19:10:40Z")

</div>

Dug deeper into this, and it looks like this could be related to instances where the API is not returning a followers and views property on the channel. Is this intended behavior? Under what conditions does the API omit that data?

```
"channel": {
  "_id": 14518599,
  "name": "afflictedstudio",
  "created_at": "2010-08-10T17:46:05Z",
  "updated_at": "2015-04-27T19:18:26Z",
  "_links": {
    "self": "https://api.twitch.tv/kraken/users/afflictedstudio"
  },
  "display_name": "Afflictedstudio",
  "logo": "http://static-cdn.jtvnw.net/jtv_user_pictures/afflictedstudio-profile_image-25f675af425c8228-300x300.png",
  "bio": "Afflicted Studios has been streaming for over 4 years. The original channel (AfflictedStudios) was established in 2009 at Justin.tv. The channel is slowly growing and maintaining loyal fans. Thank you all for your support!",
  "type": "user"
}

```

\*Looks like a user is being returned instead of a channel. The incorrect values seem to be a side effect of me not properly accounting for the missing values. Maybe you are having the same issue @ManaPot

---

<div class="post-metadata">

**Author:** ![betz0r](https://avatars.discourse-cdn.com/v4/letter/b/eb9ed0/32.png) [@betz0r](https://discuss.dev.twitch.com/u/betz0r)\
**Post date:** [May 4, 2015, 6:24am UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/13 "2015-05-04T06:24:43Z")

</div>

I can report the same issue as stream object is sometimes missing some values or . for our software to work properly we then have to make a new API call to get the correct data which should be a problem for future rate limits.

Will this be fixed, twitch?

---

<div class="post-metadata">

**Author:** ![jwmalara](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/jwmalara/32/904_2.png) [@jwmalara](https://discuss.dev.twitch.com/u/jwmalara)\
**Post date:** [May 4, 2015, 8:37am UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/14 "2015-05-04T08:37:01Z")

</div>

@betz0r,

According to @night

> This is a bug that I have already reported. The problem you are experiencing is that the user object is being returned instead of the channel object for the channel requested. Unfortunately this appears to be a caching bug, and as far as I’m aware there’s underlying technical challenges which prevent its immediate possibility of being fixed.

See this post:

> **[/streams/ returning a user object instead of channel](https://discuss.dev.twitch.com/t/streams-returning-a-user-object-instead-of-channel/2132)**
>
> This is related to Twitch API Bugged...? but I’ve since narrowed down the error and the other thread seems to have gone stale. The /streams/ and /stream/ endpoint is sometimes responding with a user object on the channel property. Seems to happen...

---

<div class="post-metadata">

**Author:** ![betz0r](https://avatars.discourse-cdn.com/v4/letter/b/eb9ed0/32.png) [@betz0r](https://discuss.dev.twitch.com/u/betz0r)\
**Post date:** [May 4, 2015, 10:33am UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/15 "2015-05-04T10:33:43Z")

</div>

I read it and can confirm channel object is often given instead of demanded stream object.

---

<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:** [June 3, 2015, 10:34am UTC](https://discuss.dev.twitch.com/t/twitch-api-bugged/2073/16 "2015-06-03T10:34:08Z")

</div>

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