1

I am making a console C# application which is supposed to check whether a Twitch Stream is online or not. I have to use Twitch API for that, I believe, which I am not very familiar with. So I need help in coming up with a solution.

I have done some research on my own to come up with a solution but most of them that I found are outdated and don't work anymore.

I do have an idea of how this is supposed to work but I can't put it in use.

First, I believe I need to download a URL string which is something like:

curl -H 'Client-ID: uo6dggojyb8d6soh92zknwmi5ej1q2' -X GET 'https://api.twitch.tv/helix/streams?first=20'

How can I achieve that in C#?

After that, the result is parsed but I'm not sure how to do that.

var r = JsonConvert.DeserializeObject<Rootobject>(json);

Maybe that's how it's done (found it on another post) but "Rootobject" has an error. Most likely it's missing something.

I am not fully sure if what I said makes sense, but in the end, I'm looking for a solution that can check if a Twitch stream is online or not.

catfood
  • 4,267
  • 5
  • 29
  • 55
  • 3
    If you get an error, you need to include the error details in your exception. You also need to show the definition of Rootobject, and a snippet of the JSON you're trying to parse. Please review [MCVE]. – mason Sep 20 '19 at 14:56
  • 1
    Check out the [HttpClient](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=netframework-4.8) which will allow you to make API calls. When you reference "another post", which post is it exactly? – MichaelM Sep 20 '19 at 15:00
  • You would need to make an API call (with application token) to an endpoint that should return a `json` string that you then would deserialize. – Trevor Sep 20 '19 at 15:06
  • I can only Deserialize the json string once I get to that point, right now I am stuck the first step. curl -H 'Client-ID: uo6dggojyb8d6soh92zknwmi5ej1q2' \ -X GET 'https://api.twitch.tv/helix/streams?first=20' how can i send this as URL. the "Client-id" needs to be sent as header but I don't know how to do that in C# – Jahanzaib Bokhari Sep 20 '19 at 15:11
  • Before, it could be done like so: "https://api.twitch.tv/kraken/streams/camoduck?client_id=xskte44y2wfqin464ayecyc09nikcj" Now, this doesn't work anymore, as kraken isn't in use anymore, Its "helix" instead and with that being in use, the client-id is supposed to be sent as header which im not sure how to do – Jahanzaib Bokhari Sep 20 '19 at 15:13
  • 3
    This is going to turn into a step-by-step help-vampire question, but check the following link for the class/setup you can use for API calls and headers: [Question](https://stackoverflow.com/questions/35907642/custom-header-to-httpclient-request/35910012) – A Friend Sep 20 '19 at 15:29
  • Thanks for that but how would you do it in the browser as well? So I can now everything is working properly before I move on to the next step in the application. – Jahanzaib Bokhari Sep 20 '19 at 15:51
  • Why would you need a browser to verify that? You could always use an independent tool like PostMan to construct a request – ADyson Sep 20 '19 at 16:12

0 Answers0