michidk / TwitchCSharp

Twitch C# Wrapper for the Twitch v3 REST API
Apache License 2.0
43 stars 12 forks source link

TwitchAuthenticatedClient - couldn't get user name! #8

Closed rafalrozek closed 8 years ago

rafalrozek commented 8 years ago

When I create a new object of TwitchAuthenticatedClient it throws a new exepction:

An exception of type 'TwitchCSharp.Helpers.TwitchException' occurred in TwitchCSharp.dll but was not handled in user code Additional information: Couldn't get the user name!

In this line: TwitchAuthenticatedClient client = new TwitchAuthenticatedClient(clientId, authKey); clientId - i have from https://www.twitch.tv/settings/connections in my app authKey - from redirected link looks like this var authKey = "1mba3xxxxxxxxxxxxxxxxxxxxxxxxx"; var clientId = "9b4gw0xxxxxxxxxxxxxxxxxxxxxxxxx";

Whats wrong?

michidk commented 8 years ago

Sadly I don't have time to maintain this project anymore. I don't know if the Twitch API changed or if you are using the API the wrong way or wrong keys / ids. I recommend to debug the 'REST' messages.

Please report back, if you found the issue!

jerotire commented 8 years ago

Using the latest version of the project (from this repo - downloaded minutes ago) and the following code (I whipped up a fresh console application project), I get no errors:

using System;
using TwitchCSharp.Clients;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var authKey = "8gcn***************";
            var clientId = "7qmx***************";

            TwitchAuthenticatedClient client = new TwitchAuthenticatedClient(clientId, authKey);

            Console.WriteLine("Username: {0}", client.GetMyUser().Name);

            Console.Read();
        }
    }
}

Apart from your Client ID or Auth Key being incorrect (as already suggested), I am unsure what the issue could be. Have you edited the TwitchCSharp project locally? Have you re-installed the Nu-Get packages Newtonsoft.Json and RestSharp? Not the best response - I know, but going to need more information to offer more assistance.

michidk commented 8 years ago

Thanks @Jerotire for testing :+1: ! Glad that this project isn't broken yet :) This error message is thrown when the user-name returned by the "GET user" request is null or empty.

To summarize, this could have multiple reasons:

The error is thrown here: https://github.com/michidk/TwitchCSharp/blob/0065cc693dead5c969115a0ae59162f5f858efae/TwitchCSharp/Clients/TwitchAuthenticatedClient.cs#L21

I admit that this isn't the best way of error handling... We should add the error message from the request (https://github.com/justintv/Twitch-API#errors) to the exception message. Also that "user == null" is unnecessary :D (because that is already handled by String.IsNullOrWhiteSpace)

rafalrozek commented 8 years ago

Wow! I reinstall RestSharp and Newtonsoft.json via NuGet and it works! <3 Thanks!