Determine if Channel is Live

With v3 of the API it was easy to determine if a channel was live with the following code (VB.NET):

Dim stringGetInfo As String = New WebClient().DownloadString(“https://api.twitch.tv/kraken/streams?client_id=MYCLIENTID&channel=” & stringTwitchID)

            'Search string to see if it contains '_id' which means there is a live stream.
            Dim index As Integer = stringGetInfo.IndexOf("_id")

            'If index is greater than 0 then pilot is streaming.
            If index < 1 Then
                stringTwitchID = ""
            End If
        End Using

With the new API, this no longer works. I have looked through all the documentation for the new API and I am unable to get anything to work.

How do I determine if a certain Twitch Channel is live?

Thanks in advance,
Marc

You can use the Get Streams endpoint to see if a stream is live https://dev.twitch.tv/docs/api/reference#get-streams

As the docs show, you have to specify your client id as a header rather than querystring param, and to specify the channel you would use either the user_id or user_login params (up to 100 channels at a time).

If a channel is live, they’ll be shown in the response, if a channel isn’t in the response then they’re offline.

I am getting the following error message:

{“error”:“Unauthorized”,“status”:401,“message”:“Must provide a valid Client-ID or OAuth token”}

Where in https://api.twitch.tv/helix/streams would I put my client ID?

As I said in my reply, and as the docs show, you have to send it as the Client-ID header

It seems this API is overly complicated for a simple task such as seeing if a particular channel is online or offline which was simple and easy to do with previous API versions.

I will have to research to see how to add a header in a VB.NET WebClient as I am getting a ‘Received an unexpected EOF or 0 bytes from the transport stream’ error message in the code I have tried so far.

Regards,
Marc

Using headers is not overly complicated, it’s a very basic part of making HTTP requests and is dealt with easily with all proper HTTP request libraries. You can even look at the docs, the curl example to use Get Streams is just 2 lines.

The sort of error you’re describing doesn’t sound like anything to do with Twitch, and most likely your code/improper use of the HTTP library you’re using.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.