Skip to content

Instantly share code, notes, and snippets.

@seanslater
Created April 11, 2020 17:04
Show Gist options
  • Save seanslater/b97ce2b3f87b486424bc23eecbbe9175 to your computer and use it in GitHub Desktop.
Save seanslater/b97ce2b3f87b486424bc23eecbbe9175 to your computer and use it in GitHub Desktop.
Twitch API - Check to see if User ID is live
<?php
$TWITCH_API_KEY = ''; // your Client ID
$TWITCHUSERID = ''; // Twitch User ID number
$url = 'https://api.twitch.tv/helix/streams?user_id='.$TWITCHUSERID;
$ch = curl_init();
$headers=['Client-ID: '.$TWITCH_API_KEY];
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec ($ch);
curl_close ($ch);
$json_array = json_encode($result);
$array = json_decode($result, true);
echo $array["data"][0]["type"];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment