Couple questions about Twitch.tv project

Couple questions about Twitch.tv project
0.0 0

#1

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?

#2

Do you mean you type “C” then click the search button and just the users you have in your recommend streams would be search and cretetion’s info would show? Or do you mean a search of all the Twitch users on the Twitch site?

If it is the latter, then you might be able to use something like:

"https://wind-bow.gomix.me/twitch-api/search/channels?query=" + search + "?callback=?"

in your code, but this will search for your entered string (i.e. “C” or “CRET”) anywhere in the channel name and not just the first letter or part of the channel name. I was not able to find an autocomplete feature of the Twitch api which is kind of what you are wanting. Search on google, someone might have developed such a feature.

See Twitch search documentation for more information.


#3

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?


#4

I think you maybe out of luck if it is case-sensitive. The only way I know of to access their data is through the API.


#5

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.


#6

I would take a look at the Twitch API documentation. I believe you can access a user’s subscribed channels.


#7

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


#8

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”.


#9

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.


#10

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…


#11

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


#12

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.


#13

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.


#14

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.


#15

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

???


#16

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


#17

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?


#18

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.


#19

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

yeah, but where on the website do i go?


#20

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.