Skip to content

Instantly share code, notes, and snippets.

@seanslater
Created April 11, 2020 17:04
Show Gist options
  • Save seanslater/cf40c6a5737944547e9131ae4df33294 to your computer and use it in GitHub Desktop.
Save seanslater/cf40c6a5737944547e9131ae4df33294 to your computer and use it in GitHub Desktop.
Twitch API - Get User ID from Username
<?php
$TWITCH_API_KEY = ''; // your Client ID
$TWITCHUSER = ''; // Twitch Username
$url = 'https://api.twitch.tv/helix/users?login='.$TWITCHUSER;
$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]["id"];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment