I’ve been attempting to integrate the Twitch API into my websites for days with no success. The documentation is nowhere near new-user-friendly. I’ve lived on these forums and Google/Reddit for literal days attempting to learn everything I can about how to integrate this API. Most of the content I find is under the old API which will be phased out later this year. As such, I’d like to develop on the new API (helix?).
My Goal: When a Twitch Channel is live, embed Twitch on the webpage. Otherwise, Twitch should never be present on the webpage.
I am by no means asking for code - I’m asking how someone as new to this as me is supposed to start learning how to integrate this API with documentation that provides zero framework for actual integration… only explaining how the API works (based on my findings, hopefully I’m missing something!).
How does one “make a request to the Get Streams endpoint”?
This is what I’m trying to resolve here - I haven’t found any useful information to answer that question throughout days of research. I know the question in it’s nature is very “noobish”, and I’m assuming an experienced developer knows exactly what you’re saying, but as someone who’s moving from simple web development to API Integration I have no idea what the answer to the above question is. Any feedback would be greatly appreciated!
API requests are literally just HTTP requests. You can can use any HTTP request library you like, such as fetch, or axios, or whatever. You just need to make the request to the endpoint you wish, with the required parameters and any optional ones as specified in the docs, and the required headers, and you’ll get back a response with JSON data.
The docs show an example:
curl -H 'Client-ID: uo6dggojyb8d6soh92zknwmi5ej1q2' \
-X GET 'https://api.twitch.tv/helix/streams?first=20'
This is the simplest way of showing a HTTP request that’s platform/language independent. It’s “Send a HTTP GET request, to the URL https://api.twitch.tv/helix/streams, with the first=20 querystring parameter, and the Client-ID: uo6dggojyb8d6soh92zknwmi5ej1q2 header.”
If you don’t yet have a Client ID, the Getting Started guide in the docs explains where to get one https://dev.twitch.tv/docs/api
So I’ve decided to work with fetch. I’ve written some code and I’ve run into the same issue I explained earlier - most examples I’ve found are with the old API. Quite literally every single example I’ve found under the new API no longer works…
Here’s what I’ve got so far (converted to pseudocode obviously), please let me know if this is the correct place to post this code or if I need to open a new thread elsewhere: https://pastebin.com/S8grYWJa
I’m getting a bunch of syntax errors for things such as “variable twitch_id/variable myclientidnumber is not defined”. Feels like I’m missing something that should be obvious here.
Thank you @Dist and @BarryCarlyon! The last part I need to solve is where to actually insert the embedded Twitch player per the example provided by @BarryCarlyon. Is there a recommended syntax?