Twitch api update, can't get ChannelId anymore?

Hi,
I am trying to get channel ID here, I cant seem to get this working, yet It should

private string GetChannel(string channel)
        {
            string result;
            using (HttpRequest httpRequest = new HttpRequest())
            {
                httpRequest.UserAgent = Http.RandomUserAgent();
                httpRequest.IgnoreProtocolErrors = true;
                httpRequest.Reconnect = false;
                for (; ; )
                {
                    
                    try
                    {
                    
                        result = Regex.Match(httpRequest.Get(string.Concat(new string[]
                        {
                        "https://api.twitch.tv/api/channels/",
                        channel,
                        "/access_token?need_https=true&oauth_token=REMOVED",
                        "&platform=web&player_backend=mediaplayer&player_type=site"
                        }), null).ToString(), "channel_id\\\\\":(.*?),\\\\\"chansub").Groups[1].Value;
                        break;
                    }
                    catch (Exception)
                    {
                        result = "";
                    }
                }
            }

Guys what am I doing wrong? Please help me I cant really wrap my head around what I am doing wrong

ADMIN EDIT: Remove oAuth Token

        public static int GetTwitchUserInfo_Helix(
                                     string channelName, //or user name
                                     ref TwitchUserInfo userInfo)
        {
            if (!string.IsNullOrEmpty(channelName) && !string.IsNullOrWhiteSpace(channelName))
            {
                string req = "https://api.twitch.tv/helix/users?login=" + channelName);
                int res = HttpsGet(req, out string buf);
                if (res == 200)
                {
                    JObject json = JObject.Parse(buf);
                    JObject j = json.Value<JArray>("data").Value<JObject>(0);
                    userInfo.DisplayName = j.Value<string>("display_name");
                    userInfo.ID = j.Value<string>("id");
                } 
                return res;
            }
            else
            {
                return 400;
            }
        }

The channel ID and the user ID is the same thing

For reference this is also not a valid/documented endpoint, I also removed your leaked access token, access tokens should never be shared and should be considered a password, as per the developer agreement

Rain has posted a valid example.

You can also refer to the documentation on Getting a Users ID by Username or oAuth token here

Excuse me,
int res = HttpsGet(req, out string buf);
HttpsGet class doesnt exist, what ref should I be using?

you must write it yourself :grinning:
method, not a class

the ref to any class which contains the id field.
alternatively, you can use a simple string instead of a class.

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