Created
April 11, 2020 17:04
-
-
Save seanslater/cf40c6a5737944547e9131ae4df33294 to your computer and use it in GitHub Desktop.
Twitch API - Get User ID from Username
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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