Twitch TV needs Authentication. Getting 403 error [Solved]

I don’t have a twitch tv account, nor do I want one. When I try getting the data, I’m getting a 403 error. Looking it up, it says that access is forbidden.
I think that I am missing a key somewhere. I’ve looked at other code, but I don’t understand what is going on. Why are some callbacks short and some long? Is it in the getJSON call that I need the key or somewhere else?

OK, I assume that you know that onlineStatus() never gets called? Since you mention the 403 error, I’ll guess that you’ve run it. Also myFunction() never gets called, and is a horrible name for a function - names should be descriptive.

That being said, when I plug the address that I used into your code, I got a good response back from Twitch.

    $.getJSON(
          "https://api.twitch.tv/kraken/streams/" +
          stream1 +
          "?client_id=5j0r5b7qb7kro03fvka3o8kbq262wwm&callback=?",
      function(data) {
        console.log(data);
      }
    );

This sends the info to your browser console .

I’m going to guess that you don’t know how to open your browser console because you had an error there. Please learn to use your browser console, it is one of the most important tools a web dev has. There error was a pretty common tether/bootstrap problem and didn’t cause your problem, but I like to clear up all errors as I go. CTRL-SHFT-J will open up your browser console on Windows.

It is called when you search in the search box. I should have name it something different.

I’m using the console log to get the errors. Also, when I try using the F12, there is too much information to parse through.

It gets called when you click on the button.

I solve one problem then move on to the next problem. Right now, I’m stuck on getting pass the 403 error. At the end, I will be condensing several methods.

Yes, callbacks can be confusing. Some are short and some are long. Some are one line long and some are pages. The purpose of the callback is to allow you to tell the program what to do with the asynchronous data you get back. Because (in the above snippet) the data will take a brief amount of time to get back, the program will finish before it gets back. The callback is a way of saying go ahead with the rest of the program, but when this JSON call is done, please call this callback function.

Yes, it’s a little weird. JS is an asynchronous language, which was very confusing for me as I’d only done synchronous languages before. But working on the web, you begin to see the logic of JS’s asynchronicity and see it’s power in a web environment.

I wrote this pen a while back to help people understand why callbacks are important for JS. Take a look and let me know if something is not clear.

Yes, I think for twitch, a key (or in this case client_id) is needed for the JSON call. Some APIs require them, some don’t. If you haven’t created a twitch account, then I’m guessing you cut and pasted this from someone else’s, which is a little inappropriate. What is your aversion to creating an account? It is free. As a web dev, you’re going to have to do this for a lot of APIs.

It gets called when you click on the button.

Then that’s a little confusing. You list a status of “offline” when you don’t know what their status is.

Thank you

I won’t use it. I see no point in creating it. Also, I don’t like how we have to sign up for a million sites while learning, I free that there could have been a better way.

Thanks for pointing that out. I didn’t think of it.

Got it working. Thank you both for your help