# Requesting stream info with Client ID in Twitch APIv5

**URL:** <https://discuss.dev.twitch.com/t/requesting-stream-info-with-client-id-in-twitch-apiv5/11364>\
**Category:** API\
**Created:** [August 8, 2017, 2:29pm UTC](https://discuss.dev.twitch.com/t/requesting-stream-info-with-client-id-in-twitch-apiv5/11364 "2017-08-08T14:29:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![snowfun87](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@snowfun87](https://discuss.dev.twitch.com/u/snowfun87)\
**Post date:** [August 8, 2017, 2:29pm UTC](https://discuss.dev.twitch.com/t/requesting-stream-info-with-client-id-in-twitch-apiv5/11364/1 "2017-08-08T14:29:12Z")

</div>

how can I implement my client-ID in my request to the twitch API servers via PHP?

This is my current code:  
$clientid=“xxxxxxxxx”;  
function is\_channel\_live($channel)  
{  
$request = json\_decode( @file\_get\_contents( ‘[https://api.twitch.tv/kraken/streams/](https://api.twitch.tv/kraken/streams/)’ . $channel ) );  
return ( ! is\_null( $request-\>stream ) ) ? TRUE : FALSE;  
}  
$chan = “shroud”;  
if (is\_channel\_live($chan)==true)  
echo “Live!!”;

```
else
echo "Offline..";

```

How would I actually implement the client ID in the request?

May also note that I am very new to the twitch API…

---

<div class="post-metadata">

**Author:** ![DallasNChains](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dallasnchains/32/1608_2.png) [@DallasNChains](https://discuss.dev.twitch.com/u/DallasNChains)\
**Post date:** [August 8, 2017, 2:34pm UTC](https://discuss.dev.twitch.com/t/requesting-stream-info-with-client-id-in-twitch-apiv5/11364/2 "2017-08-08T14:34:47Z")

</div>

There is a PHP example in the [Client-ID blog post](https://blog.twitch.tv/client-id-required-for-kraken-api-calls-afbb8e95f843). See if that helps!

---

<div class="post-metadata">

**Author:** ![Ague](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ague/32/2428_2.png) [@Ague](https://discuss.dev.twitch.com/u/Ague)\
**Post date:** [August 8, 2017, 11:34pm UTC](https://discuss.dev.twitch.com/t/requesting-stream-info-with-client-id-in-twitch-apiv5/11364/3 "2017-08-08T23:34:46Z")

</div>

I would def recommend using a cURL library like in the example that @DallasNChains recommended. If you don’t want to use cURL directly, there are several good third party libraries out there (Guzzle & Unirest, to name a couple off the top of my head). They will allow you to easily parse headers so you can do quick checks for `200` and `404`, rather than just suppressing any errors that come up retrieving the data.

But if you absolutely insist on using `file_get_contents`, you need to include the API version and client id inline in the URL like this (79462105 is my channel, so don’t copy and paste verbatim):

`https://api.twitch.tv/kraken/streams/79462105?client_id=xxxxxxxxxx&api_version=5`

And don’t forget to have the `api_version=5` in your query parameters as the default is still v3.

Hope this helps

---

<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:** [September 7, 2017, 11:34pm UTC](https://discuss.dev.twitch.com/t/requesting-stream-info-with-client-id-in-twitch-apiv5/11364/4 "2017-09-07T23:34:53Z")

</div>

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