[C#]Getting Twitch Json Requests

For the past 2 days I’ve been attempting to get the followers count on a channel and put them into a label as text in visual studio. I couldn’t figure it out so I thought I could use the jsons that everybodies been talking about… I have no idea how to do that either.
This is my code so far:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TwitchLib.Api;
using TwitchLib.Api.Helix.Models.Users;
using TwitchLib.Api.V5.Models.Subscriptions;

namespace WindowsFormsApp1
public partial class Form1 : Form
string followercount = “”;
public Form1()

    public void Label1_Click(object sender, EventArgs e)

    public void Button1_Click(object sender, EventArgs e)

    private static TwitchAPI api;

    private void MainNot()
        api = new TwitchAPI();
        api.Settings.ClientId = "xqfi26zgghfrnf24n5euh6xxklr3hw";
        api.Settings.AccessToken = "47m0qbg6fw1sd6uxvhcbapdzqvt63n";
    public static async Task CallsAsync()
        //Checks subscription for a specific user and the channel specified.
        Subscription subscription = await api.V5.Channels.CheckChannelSubscriptionByUserAsync("channel_id", "user_id");

        //Gets a list of all the subscritions of the specified channel.
        List<Subscription> allSubscriptions = await api.V5.Channels.GetAllSubscribersAsync("channel_id");

        //Get channels a specified user follows.
        GetUsersFollowsResponse userFollows = await api.Helix.Users.GetUsersFollowsAsync("user_id");

        //Get Spedicified Channel Follows
        var channelFollowers = await api.V5.Channels.GetChannelFollowersAsync("elixist");

        //Return bool if channel is online/offline.
        bool isStreaming = await api.V5.Streams.BroadcasterOnlineAsync("channel_id");

        //Update Channel Title/Game
        await api.V5.Channels.UpdateChannelAsync("channel_id", "New stream title", "Stronghold Crusader");


I applaud your desire to make use of the Twitch API, but there are several issues with your code.

You invoke neither MainNot nor CallsAsync. Since you copied this verbatim from the TwitchLib repository, I understand why you renamed Main to MainNot. However, that example code as given in the repository, is incomplete and incorrect.

Your click handlers are empty. You don’t need Label1_Click since you don’t need such a handler for your label. (It’s rare to ever need such a handler.) Button1_Click is where you want to invoke CallsAsync. In Button1_Click, add this line: var task = CallsAsync();.

The invocation of GetChannelFollowersAsync is incorrect. It does not accept channel names, only channel IDs. That method fails silently if given a channel name. Replace elixist with 66227321.

Move the contents of the MainNot method into the Form1 constructor. Since you care only about getting the follower count for a channel, delete all code from CallsAsync except the invocation of GetChannelFollowersAsync. After that line, add this line: Label1.Text = channelFollowers.Total.ToString();. Now, you are ready to run the application and click the button.

Also, you have leaked an access token for your application. I suggest you invalidate it immediately to prevent someone from using it for nefarious means. In future posts, do not include an access token.

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