Cant Get UserID in C#

Hey there,
i got some problems by getting the UserID “GET” with C# on api v5.

Other requests for channel/channelname or something like that works great, but on user?login i got
the status 404 back.

For the moment i do it like that.

on my Dll file:
public TwitchReadOnlyClient(string clientID, string url = TwitchHelper.twitchApiUrl)
restClient = new RestClient(url); // url = “
restClient.AddHandler(“application/json”, new DynamicJsonDeserializer());
restClient.AddHandler(“text/html”, new DynamicJsonDeserializer());
restClient.AddDefaultHeader(“Accept”, TwitchHelper.twitchAcceptHeader); // “application/vnd.twitchtv.v5+json”;
restClient.AddDefaultHeader(“Client-ID”, clientID);

    public Users GetUser(string username)
        var request = GetRequest("users?login={username}", Method.GET);
        request.AddUrlSegment("username", username);
        var response = restClient.Execute<Users>(request);
        return response.Data;

on my main programm:

private static string userName = "xxxxx";
private static string password = "oauth:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private static string channel = "xxxxxxxx";
private static string TwitchClientID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private static string oauthKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

TwitchReadOnlyClient TwitchROClient = new TwitchReadOnlyClient(TwitchClientID);

// to test call funktion by button click
private void button1_Click(object sender, EventArgs e)
    var myUser = TwitchAuthClient.GetUser(userName); /// <<< probem dont give me response error 404
    var IDChannel = TwitchROClient.GetChannel(channel); // works fine for the moment with the ChannelName. With ID there will be the same 404 status            
var request = GetRequest("users?login={username}", Method.GET);

missing a $ in there for the string interpolation

var request = GetRequest($"users?login={username}", Method.GET);

Would generally help to also know where the RestClient and GetRequest are coming from.

hey thx for the fast reply but there is no change with or without $

on my other fuction Channel by ID
public Channel GetChannel(string channel)
var request = GetRequest(“channels/{channel}”, Method.GET);
request.AddUrlSegment(“channel”, channel);
var response = restClient.Execute(request);
return response.Data;
it works fine

RestClient comes from RestSharp and get Created in the Constructor of TwitchReadOnlyClient

    public TwitchReadOnlyClient(string clientID, string url = TwitchHelper.twitchApiUrl)
        restClient = new RestClient(url);
        restClient.AddDefaultHeader("Accept", TwitchHelper.twitchAcceptHeader);
        restClient.AddDefaultHeader("Client-ID", clientID);

and GetRequest is a simple Interface

public interface ITwitchClient
RestRequest GetRequest(string url, Method method);
Main class:
public RestRequest GetRequest(string url, Method method)
return new RestRequest(url, method);
RestRequest also comes from RestSharp

okay Problem sloved im just to stupid

I have to add a new class

namespace TwitchDll.Models
public class UsersID : TwitchResponse
public List Users { get; set; }

before i used the normal Users class

1 Like

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