Couple questions about Twitch.tv project

https://codepen.io/Mike-was-here123/full/MOmKzO/ --> is my codepen

  1. First of all, how come my link for going to their page isn’t working for going to their channel? (line 29, 35, 64, 67) data2._links.self was what i used and i get:
    {"error":"Bad Request","status":400,"message":"No client id specified"}

  2. Is their anyway i can make it so when i search, for example, C, it searches for all the channels that start with C, not just any channels that their complete name is C. Also not case sensitive

  3. If no results are found, how do i change that h3 text based uon that? I’m having a issue with testing that their is no results. This is what i tried (doesn’t work, line 58):

if (data == undefined) {
          document.getElementById("ThatRandomText").html("No results found...")
        }
  1. Any random channel search?

I mean like if I type C, it searches all of twitch for streamers that start with C and c. Currently it searches all of twitch, but needs to be exactly their name. StarWarsHQ works, but starWarsHQ doesn’t. I didnt see anything about twitch auto-complete. Is their anyway to access their servers/ data base?

Oh okay…

Is their anyway i can search up a similar result. Or vary their result until find a match?

I mean their getting their data from somewhere, so there must be a way.

Plus how does auto complete work? I could always apply it here even if it isn’t a api.

Is their anyway i can access the users subscribe channels? Like they input their channel name, and i use who they follow as suggestions.

Okay thanks, i’m interested in anything you come up with :smiley:

Hi,
The Twitch api has changed a few times over the past year.
404 or 400 status codes means that it is not found or doesn’t exist. You will see these for the “Closed Accounts” users.

Here is the current api that I know works at the moment:
//Main ajax function that request for streams/user.
$.ajax({
url: https://api.twitch.tv/kraken/streams/’ + user
, dataType: “json”
, headers: {
‘Client-ID’: ‘PLACE you CLIENT ID here’
}
//Check Account Closed
, statusCode: {
404: function (xhr)
{

//if user offline this secondary Ajax function is used for channels/user.
$.ajax({
url: https://api.twitch.tv/kraken/channels/’ + user
, dataType: “json”
, headers: {
‘Client-ID’: ‘PLACE you CLIENT ID here’

And you should also be checking to see if freeCodeCamp is online or not:
https://api.twitch.tv/kraken/streams/freecodecamp?client_id=PLACE you CLIENT ID here?”,

I am not certain how to get every user beginning with “c”.

1 Like

I am able to get their status of offline or online. I basically have a working api. My only issues, as i said before was going to their webpage. They JSON provides a link, which i used.

https://api.twitch.tv/kraken/channels/storbeck
https://api.twitch.tv/kraken/channels/habathcx
https://api.twitch.tv/kraken/channels/cretetion
https://api.twitch.tv/kraken/channels/noobs2ninjas
https://api.twitch.tv/kraken/channels/freecodecamp
https://api.twitch.tv/kraken/channels/robotcaleb

These links should work.?? If they don’t i’m petty annoyed on how they just change a api and screw us over like this. If it says robotcaleb in the url, go to robotcaleb profile. I’m not hacking the pentagon, no need to give me a error.

Ah you almost have it.

kraken/streams + streamers should give you those who are online
kraken/channels + streamers should give you those who are offline.

These are online: “ESL_SC2” and “OgamingSC2”.
These are not found and should be in the Account Closed list: “brunofin”, "comster404"
The others are currently offline, including freeCodeCamp

The only other thing I can see is that you need a Twitch Client ID. It should be shown in each api call and in its header. Both places.

That is what changes were made this past year.

I know it’s frustrating…

So the only thing i would need to add is the client id to my current code and that is it?

yes. see how I did it above? In that api call at the end and the ajax json header “PLACE Your CLIENT ID here”

If you are pulling in the correct information on those streamers, then this may be all that is missing.

I put

    $.ajax({
           dataType: "json",
           headers: {
             ClientID: data2_ID
           }
         });

on lines 29 - 34 of my code https://codepen.io/Mike-was-here123/pen/MOmKzO

It works, but only for streamers online. The streams offline never show up on my html.

To get the Account Closed you need to check the status :
after headers ClientID:
}
//Check Account Closed
, statusCode: {
400: function (xhr)
{
console.log(user + " has no account");

You need to do the same thing that you did for the online streamers but check the channels of the missing streamers:
kraken/channels + streamers

It should work then.

Okay this is my code. It was working before for the online streamers, but only because it had no client ID since i forgot a period between data2 and _ID.

Now i still want to push the users on the page who are offline. I am already currently doing this, but as i said before, the link isn’t working.

  $.ajax({
            dataType: "json",
            headers: {
              ClientID: data2._ID
            },
            statusCode: {
              400: function(xhr) {
               console.log(streamers[i]+ " has no account");
              }
            }
          });

Also

You need to do the same thing that you did for the online streamers but check the channels of the missing streamers:
kraken/channels + streamers

???

Did you try this?

$.ajax({
url: ‘https://api.twitch.tv/kraken/channels/’ + user
, dataType: “json”
, headers: {
‘Client-ID’: ‘PLACE you CLIENT ID here’

Here’s a link to my current Twitch.tv : https://codepen.io/KoniKodes/pen/pbPvGj

Okay now both my offline and online streamers pop up. Only online streamers links work. I wanted the offline to link the profile, and online link to their stream(which it does link to stream)

I’m still getting the {"error":"Bad Request","status":400,"message":"No client id specified"} only for offline streamers.

This is how i pasted your code

$.ajax({
            url: "https://api.twitch.tv/kraken/channels/" + streamers[i],
            dataType: "json",
            headers: {
              'Client-ID': 'PLACE you CLIENT ID here'
            }
          });

How can i get my client ID?

You need to get the client id from twitch. Isn’t yours data2_ID?

If you don’t have one, then this two link may be helpful:

Do note that it must be used in the api call as well as the header of the ajax.

1 Like

So i go their and it says its been moved too --> https://dev.twitch.tv/

yeah, but where on the website do i go?

you should use ajax on twitch v5 api. you also need to read their docs. i don’t recommend to use the new api. its very confusing.

1 Like

The only thing i need at this point is a Key, because offline streamers don’t link to their profile. I tried many things at this point. I shouldn’t need all this stuff just to put in a freakin link. Like really??? I’m starting to think this is a ego thing.

if streamer is offline so twitch will return null means he/she offline. you could go to the channel page in their api to get another information like logo img…etc

1 Like

I should just be able to link to their own profile.