# PHP check to see if stream is live not working

**URL:** <https://discuss.dev.twitch.com/t/php-check-to-see-if-stream-is-live-not-working/27152>\
**Category:** API\
**Created:** [July 16, 2020, 6:04am UTC](https://discuss.dev.twitch.com/t/php-check-to-see-if-stream-is-live-not-working/27152 "2020-07-16T06:04:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mave](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/mave/32/9670_2.png) [@Mave](https://discuss.dev.twitch.com/u/Mave)\
**Post date:** [July 16, 2020, 6:04am UTC](https://discuss.dev.twitch.com/t/php-check-to-see-if-stream-is-live-not-working/27152/1 "2020-07-16T06:04:50Z")

</div>

Can anyone point me in the right direction? I know I’m close but this code isn’t working yet.

EDIT: I figured out what’s wrong (I think), but need helping implementing it. Oauth is missing, I have no idea on how to include this here though or how to generate the Oauth code.

```
<?php
// Options

$clientID = 'MY_SECRET_CLIENT_ID';
$channelName = 'mavemixes';

$baseURL = 'https://api.twitch.tv/helix/';
$url = $baseURL . 'streams?user_login=' . $channelName;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Client-ID: ' . $clientID]);
$json = curl_exec($ch);
curl_close($ch);

$data = json_decode($json);
if(count($data->data)) {
	echo '<h1>We're live!</h1>';
	echo '<div id="twitch-embed"></div>';
}else{
	echo '<h3>Currently not streaming. <br>Follow MaveMixes on Twitch and get instantly notified when we are live.</h3>';
	
}
?>

```

```
<script>
  new Twitch.Embed("twitch-embed", {
    width: 1000,
    height: 600,
    channel: "mavemixes",
    layout: "video",
  });
</script>

```

Thanks in advance!

---

<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:** [July 16, 2020, 10:41am UTC](https://discuss.dev.twitch.com/t/php-check-to-see-if-stream-is-live-not-working/27152/2 "2020-07-16T10:41:19Z")

</div>

Documentation is here

> **[Authentication](https://dev.twitch.tv/docs/authentication/)**
>
> Authentication

You probably want to be generating storing and using until expires an app access token

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

---

<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:** [August 15, 2020, 10:41am UTC](https://discuss.dev.twitch.com/t/php-check-to-see-if-stream-is-live-not-working/27152/3 "2020-08-15T10:41:21Z")

</div>

Closed on August 15, 2020, 10:41am UTC

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