I am new to JS and even more new to APIs. I have a node.js discord bot (running locally at home) on my discord server and I want to incorporate a feature that will send an embed on a specific discord channel when someone on my server goes live on twitch. I want to use API to do it.
My issue is i get authentication errors when I try the example url located here. I am also not sure what I need to have my oauth redirect to be.
Ok. So I would need a html send and request for JavaScript and send that at the beginning? Then it should respond with a json that I can save and use for my token. Is there other things I need to authenticate a channel request? And how would I save the responses from Twitch? Would I need a database like program on the bot as well?
Sorry if theses questions seam quite simple but I really don’t know what I’m doing. Thanks again
So I would run the post once for server to server and use the return key for my requests?
What is the difference in information that Webhooks provide from long-pulling?
Also how would the request look different for long pulling and Webhooks. For Webhooks they showed this: “ /api/webhooks-reference/#subscribe-tounsubscribe-from-events” if I wanted to subscribe to a specific streamer how would I write it out and include my key.
And finally, how to I capture a response form Twitch? Would I need an async function to await for some response?
The webhook sends the same payload as the streams API would
You make a request to the Webhooks hub to create a subscription (which remains active for up to 10 days). Then when the stream goes online/offline/changes title you get a POST’ed payload to your Callback
The structure of the POST to create a webhook subscription, for the headers is the same as any API request to Helix.
You just need to POST a JSON blob that tells Twitch what topic you want and how long you want it for. And setup a callback handler to receive (and verify the subscription)
For long polling you just load the streams API once per minute every minute, (wasting resources and API requests), Webhooks you get data when data changes as Twitch tells you data has changed.
You make a POST to Twitch at https://api.twitch.tv/helix/webhooks/hub with a App access Token and ClientID in the header, with a JSON blob similar to whats above, you get a 204 (No Content) or a 202 Accepted (I forget which offhand)
Twitch makes a GET request to your callback URL, to check that it’s valid, Twitch includes a hub.challenge as a Query string parameter
You Echo back that challenge
Then when data occurs, Twitch will make a POST to your callback with the data.
and I got my key back. Do I have to rerun that every month or so because it looks to have an expiration?
Now I have to change my other code to do fetch() and set up a handler for when Twitch responds. Can I use express for the handler? And am I missing anything else? Thanks
Ok, a few more questions regarding the subscribe request:
For the callback URL, can it be either a DomainName:port or a PublicIP:port? Or is it something different?
What is the hub.secret? is it something i can define and how does it work?
Is is possible to subscribe to multiple users in one request or do I need to make it run everytime for every user? If i can do it in one command, what would the format look like? If every user, what is the best way of accomplishing this because i don’t just want to paste the code in 10 different times and change the user part.
I’m not all that familiar with SSL and I just have a public IP and port forwarding(Because I’m hosting locally from home). But having 'hub.callback': 'http://<PUBLIC_IP>:8000', will work?
long poll and wait for the data to change basically? Would I log the times when data is received to compare the differences? Also i believe i can pull multiple users at once by just long pulling right?