I Don't Know how to use the new Helix Twitch api


Can i please know if this is the right Syntax , i already check the guide but am not getting anything
except this : {“error”:“Unauthorized”,“status”:401,“message”:“Must provide a valid Client-ID or OAuth token”}

To be specific i would like to know the Syntax to get a Streamer infos like
followers count
viwers count
Please & thank you

You can’t send the client id as a querystring param, you have to send it as the Client-ID header, as shown in the example https://dev.twitch.tv/docs/api/reference#get-streams Also you can’t use multiple ? in a querystring, you use the question mark symbol once to indicate the start of the querystring, and then an ampersand & to separate separate parameters.

To see the follower count you would use the Get User Follows endpoint https://dev.twitch.tv/docs/api/reference#get-users-follows with the to_id param that is the id of the user you wish to see who follows them.

Hello Sir , sorry for disturbing you again but i’m not really quiet good at web programming i know only php html css and i don’t really know wich programming language am gonna have to use for this twitch api to get a channel data (followers count ,viewers count , profile picture etc …) i wanna store this data in mysql database so please if you show a project example on how to use the twitch api on a website and how to take the data in JSON format and use it in PHP . i’m really tripping looking for tutorials i couldn’t find any . Thank you in advance !

Basic PHP cURL to fetch a URL and process the response


$ch = curl_init('https://api.twitch.tv/helix/streams?user_login=Channel_name');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Client-ID: MyClientId'

$data = curl_exec($ch);
$info = curl_getinfo($ch);

if ($info['http_code'] == 200) {
    $data = json_decode($data);
} else {
    echo 'Failed with ' . $info['http_code'];

See also

Google Search: php fetch from api
Second Result: https://stackoverflow.com/questions/33302442/get-info-from-external-api-url-using-php/33303776

1 Like

Thank you So Much Sir for helping me out , this code of curl with php made things so easy for me i finally can’t understand how to use the api on php . but there is one last think i don’t understand wich is why i am not getting any infos in the data . i checked twice my client id , and i changed user_login with many streamers ids like ninja to test but sadly the array is empty . Thanks again :slight_smile:


The example code I presented and the URL you used in OP, checks for a Live Stream, if the user is not live, no data is returned.

Do you perhaps mean the users API instead

1 Like

Sir You can’t imagine how glad i am after the api finally worked for me , omg i can’t even believe it ^^
i was struggling with it for hours maybe 15 hours non stop until now .
Thank you again for your wonderful support <3


Here is a front-end example… Maybe it is help to you or anyone else…

"use strict";
// type = the response format JSON or text
const callAJAX = (props) => {
    const url = props.url,
          method = props.method || "GET",
          type = props.type || "JSON",
          header = props.header
    return new Promise(waitForResult => {
        const xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (this.readyState === 4 && this.status === 200) {
                type === "text" 
                    ? waitForResult(this.response)
                    : waitForResult(JSON.parse(this.response))
        if (method === "GET") {
            xhttp.open("GET", url, true);
            for (const key in props.header) {
                xhttp.setRequestHeader(key, header[key]);

const AJAXProps = {
    url: "https://api.twitch.tv/helix/streams?first=20",
    header: {"client-ID": "--- your client id goes here ---"}

// Get Streams: -----------------------------------------------------------
callAJAX(AJAXProps).then(response => {
    console.log("streams", response);

// Get Streams Metadata: -----------------------------------------------------------
AJAXProps.url = `https://api.twitch.tv/helix/streams/metadata`;
callAJAX(AJAXProps).then(response => {
    console.log("metaData", response);

// Get All Stream Tags: -----------------------------------------------------------
AJAXProps.url = `https://api.twitch.tv/helix/tags/streams?first=20`;
callAJAX(AJAXProps).then(response => {
    console.log("streamsTags", response);

// Get specified stream Tags: -----------------------------------------------------------
let broadcasterID = "110690086"; // is it the user ID ???
AJAXProps.url = `https://api.twitch.tv/helix/streams/tags?broadcaster_id=${broadcasterID}`;
callAJAX(AJAXProps).then(response => {
    console.log("specified stream Tags", response);

// Get Users: -----------------------------------------------------------
const userID = 110690086; // multiple id's query separate with ampersans (&id=...&id=...)
AJAXProps.url = `https://api.twitch.tv/helix/users?id=${userID}`;
callAJAX(AJAXProps).then(response => {
    console.log("get User by ID", response);
const loginName = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas", "myth"];
let names = "";
while (loginName.length) {
    let name = loginName.pop();
        ? names += name
        : names += `&login=${name}`
AJAXProps.url = `https://api.twitch.tv/helix/users?login=${names}`;
callAJAX(AJAXProps).then(response => {
    console.log("get User by login name:", response);

// check if users now streaming:
AJAXProps.url = `https://api.twitch.tv/helix/streams?first=20&user_login=${names}`.replace(/login/g, "user_login");
callAJAX(AJAXProps).then(response => {
    console.log("check if the given users now streaming", response);

// Get Users Follows: -----------------------------------------------------------
const fromID = 30104304; // this is the dataset of followed users???
const toID = 110690086; // this is the dataset of followers???
AJAXProps.url = `https://api.twitch.tv/helix/users/follows?from_id=${fromID}`;
callAJAX(AJAXProps).then(response => {
    console.log("Get User Follows from:", response);
AJAXProps.url = `https://api.twitch.tv/helix/users/follows?to_id=${toID}`;
callAJAX(AJAXProps).then(response => {
    console.log("Get User Follows to:", response);

// Get Clips: -----------------------------------------------------------
const clipID = 110690086; //  one or more; Which data need here? Where can I find  the clip's ID???
broadcasterID = 110690086; // one only; ... and here??? 
let gameID = 33214; // one only
AJAXProps.url = `https://api.twitch.tv/helix/clips?id=AwkwardHelplessSalamanderSwiftRage`; // static ID from sample code
callAJAX(AJAXProps).then(response => {
    console.log("Get Clips", response);
AJAXProps.url = `https://api.twitch.tv/helix/clips?game_id=${gameID}`;

callAJAX(AJAXProps).then(response => {
    console.log("Get Clips by game ID", response);

// Get Game: -----------------------------------------------------------
gameID = 490422;
let gameName = "Fortnite";
AJAXProps.url = `https://api.twitch.tv/helix/games?id=${gameID}`;
callAJAX(AJAXProps).then(response => {
    console.log("Get Game by ID:", response);
AJAXProps.url = `https://api.twitch.tv/helix/games?id=${gameID}`;
callAJAX(AJAXProps).then(response => {
    console.log("Get Game by Name:", response);

// kraken channels -----------------------------------------------------------------------
AJAXProps.header["Accept"] = "application/vnd.twitchtv.v5+json";
AJAXProps.url = `https://api.twitch.tv/kraken/channels/30220059`;
callAJAX(AJAXProps).then(response => {
    console.log("kraken channels", response);