How to Get Channel Information

Hello! I am trying to get the information of one or more channels through the API. But I don’t know how it works. I have look the guide (https://dev.twitch.tv/docs/v5/reference/channels#get-channel) and also looked at the forums. A few years ago I managed to do the same with the youtube API using PHP. I’m trying to get the same thing this time with Twitch channels but without success, for the moment. I don’t know how Json works.

I see the code in the guide but I do not know how to translate it into a working file online. Can I put this code on my server and execute it to get this information in a php file or something? My intention is to extract the result info data using php functions.

Reach this point:

curl -H 'Accept: application/vnd.twitchtv.v5+json'
-H 'Client-ID: MyChannel-ID'
-X GET 'https://api.twitch.tv/kraken/users?login=Channelname'

I’m triyng to put this code working on a php file or similar, and when the php is executed in my server, displays the information of the specific channel. Same info of this example: https://dev.twitch.tv/docs/v5/reference/channels#get-channel

Thank you very much!

If you are familiar with file_get_contents, you can sub it out with something like this:

<?php


/* file_get_contents replaced with curl function - Add this function and replace any use of file_get_contents with file_get_contents_curl */
function file_get_contents_curl($url) {
    $curlHeader = array(
        "Client-ID: xxxxxxxxxxxxxxxxxxxxxxxxxx",    /* SET CLIENT ID HERE */
        "Accept: application/vnd.twitchtv.v5+json",
        "Authorization: OAuth xxxxxxxxxxxxxxxxxxxxxxxxxxx"
    );
    $ch         = curl_init();
    curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeader);
    $data = curl_exec($ch);
    if (!curl_errno($ch)) {
      switch ($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
    case 200:  # OK
      break;
    default:
      echo 'Unexpected HTTP code: ', $http_code, "\n";
  }
}
    curl_close($ch);
    return $data;
}

?>

Remove the OAuth for your purpose, it’s just there for the example.

OMG! It worked !! Now I can continue working. Thank you very much for the help and collaboration :smiley: really appreciated

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