We would like to show the current live streams for Soccer Battle within the Unity game iteself.
The following looks to be the right API call to use:
Our game is written in Unity using C# and we are doing the following call using the Authorization and Client-Id shown in the link above.
UnityWebRequest webRequest = new UnityWebRequest();
DownloadHandlerBuffer dhb = new DownloadHandlerBuffer();
webRequest.downloadHandler = dhb;
webRequest.SetRequestHeader("Authorization", "Bearer 2gbdx6oar67tqtcmt49t********");
webRequest.url = "https://api.twitch.tv/helix/streams";
yield return webRequest.SendWebRequest();
When we make this call we get the following error response.
"message": "Invalid OAuth token"
I understand there is some type of authentication token needed? What are the exact steps to do this? It seems pretty complicated just for getting a list of live streams.
Authentication is covered here, and there are a few forms of auth depending on what you need to do.
The Token in that example, in the docs is an example token, so not a valid one to use. It’s display in the docs so people know how to correctly format the call.
You need to replace the ClientID with your ClientID and generate a valid token.
In order to generate a token in your game, in order to call the API, you will need to ask the user to login with Twitch, otherwise you won’t have a token to use.
Alternatively your game can phone home to your server and your server can use an App Access Token to fetch the channels live with your game.
DO NOT GENERATE AN APP ACCESS/CLIENT CREDENTIALS TOKEN IN THE GAME ITSELF as this would mean you are leaking your Client Secret in your game.
So you have two options:
The second option is more practical as you’d use a CronJob to generate the list of live streams, and doesn’t require the player to login to Twitch (if the player even has a Twitch account) and just write a JSON file that your game can fetch as needed and the CronJob updates that list. This also means your stream dispaly doens’t need to wait for token generation and/or the API to return data, as you already generated a cache file for the game to use to build out the list of streamers live.
That is what the “Extension in Action” list on my Extension information page over at IGDB.com Game Information | Twitch Extensions uses.
A CronJob using an app access token to generate a JSON file located at
https://twitch.extensions.barrycarlyon.co.uk/igdb/streams.json, in this example calling the “Live Activated Channels with my extension” rather than a “what channels are live with my game” but the principal is the same, periodically build a JSON file for the frontend to use, and then the frontend has no visible token anywhere, meaning no Twitch Login by the user or a leaked client secret.
Thank you for the detailed explanation!
Asking the user to log into Twitch does not make sense for our use case. And we don’t have the development resources to setup a server side solution.
If Twitch or a 3rd party ever sets up a service with a simple web call, we will look forward to using it!
Such a thing would likely fall afoul of the developer agreement (resyndication of Twitch content)
The intened way to do this is to run the service that provides the data you need yourself using the documentation authentication proceedures. And then you don’t have to rely on someone elses service be stable/etc
So I don’t expect someone will provide a service you can just use but might provide an example you can copy to your own server and run with your own ClientID/Secret.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.