Coder Social home page Coder Social logo

twitchlib.api's Introduction

TwitchLib.Api

API component of TwitchLib.

For a general overview and example, refer to https://github.com/TwitchLib/TwitchLib/blob/master/README.md

using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using TwitchLib.Api;
using TwitchLib.Api.Services;
using TwitchLib.Api.Services.Events;
using TwitchLib.Api.Services.Events.LiveStreamMonitor;

namespace Example
{
    public class LiveMonitor
    { 
        private LiveStreamMonitorService Monitor;
        private TwitchAPI API;

        public LiveMonitor()
        {
            Task.Run(() => ConfigLiveMonitorAsync());
        }

        private async Task ConfigLiveMonitorAsync()
        {
            API = new TwitchAPI();                
                
            API.Settings.ClientId = "";
            API.Settings.AccessToken = "";               

            Monitor = new LiveStreamMonitorService(API, 60);      

            Monitor.OnStreamOnline += Monitor_OnStreamOnline;
            Monitor.OnStreamOffline += Monitor_OnStreamOffline;
            Monitor.OnStreamUpdate += Monitor_OnStreamUpdate;

            Monitor.OnServiceStarted += Monitor_OnServiceStarted;
            Monitor.OnChannelsSet += Monitor_OnChannelsSet;

            List<string> lst = new List<string>{ "ID1", "ID2" };
            Monitor.SetChannelsById(lst);      

            Monitor.Start(); //Keep at the end!

            await Task.Delay(-1);

        }

        private void Monitor_OnStreamOnline(object sender, OnStreamOnlineArgs e)
        {
            throw new NotImplementedException();
        }

        private void Monitor_OnStreamUpdate(object sender, OnStreamUpdateArgs e)
        {
            throw new NotImplementedException();
        }

        private void Monitor_OnStreamOffline(object sender, OnStreamOfflineArgs e)
        {
            throw new NotImplementedException();
        }

        private void Monitor_OnChannelsSet(object sender, OnChannelsSetArgs e)       
        {
            throw new NotImplementedException();
        }

        private void Monitor_OnServiceStarted(object sender, OnServiceStartedArgs e)
        {
            throw new NotImplementedException();
        }        
    }
}

twitchlib.api's People

Contributors

hampo avatar hantick avatar honestdan avatar iprodigy avatar itssimple avatar jaybyrrd avatar jmbowman1107 avatar joakimwehype avatar johngames avatar kamparr avatar kamyker avatar luckynos7evin avatar mahsaap avatar moritzuehling avatar mtleliever avatar myroot avatar nickcraver avatar pietrodicaprio avatar pixlcrashr avatar prom3theu5 avatar ritzmo avatar rrickkert avatar sollaholla avatar swiftyspiffy avatar syzuna avatar terasol avatar teravus avatar urantij avatar wreckedarrow avatar yartch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twitchlib.api's Issues

RefreshResponse ExpiresIn is always 0

Hey, I am using the following code on the latest lib version (2.1.4)

var authToken = TwitchApi.Auth.v5.RefreshAuthTokenAsync(refreshToken, clientSecret).GetAwaiter().GetResult();

And the response it gives always have the ExpiresIn field set to 0.

TwitchApi.V5.Chat.GetAllChatEmoticonsAsync throws BadRequestException

Got an BadRequestException using method TwitchApi.V5.Chat.GetAllChatEmoticonsAsync()

Update: if dont push AccessToken (comment line in code), i get result from API. But this result was unable to deserialize:

Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'TwitchLib.Api.V5.Models.Chat.EmoticonImage[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'emoticons[0].images.emoticon_set', line 1, position 129.

Update2: If save response json to file it took ~120Mbytes

Bits.helix.GetBitsLeaderboardAsync throws NullReferenceException

I've initialized the client and set the accesstoken and clientid but when using the command TwitchAPI.Bits.helix.GetBitsLeaderboardAsync(1, TwitchLib.Api.Enums.BitsLeaderboardPeriodEnum.Week); I get a System.NullReferenceException from TwitchLib.Api.ApiSettings,DynamicScopeValidation.

EDIT: To make it clear, I don't call it like a static function in the actual code

Custom Room Message

Hello.
I can not get the bot to send a message to custom rooms. After Connect to Room (client.JoinRoom(channelName, "market"), messages are still sent to stream chat. Thx for help

Better way of setting Creds for Api

At the moment we have an Initialise Method which sets creds and checks them against the Api

I would like to remove this and instead enable setting of the creds through Api.Settings.ClientId and Api.Settings.AccessToken however include a "CheckCredentials" method which does just that. Returning a KeyValuePair<bool, string>

[Broke]{Dev Branch} Helix change for the monitor broken

Not sure how I missed this but its not triggering event on detecting a channel online. It does however detect the online channels correctly in the library code. GetLiveStreamersAsync works. Its CheckForOnlineStreamChangesAsync not working atm.

I'm still investigating, but to ensure the lib is not pushed to nuget or to master till this is fixed, I'm adding this issue.

Follower Service Always Reporting New Followers

When I start a FollowerService and watch the OnNewFollowerDetected event, it always starts off by reporting 100 new followers. They're not new followers. I don't think it's setting its cache when the service starts. This means it always considers everyone to be "new" for the first trigger of the event.

This is the version of TwitchLib I am referencing.

    <PackageReference Include="TwitchLib" Version="3.0.1" />

HandleWebException in TwitchHttpClient should throw a more useful error message on HTTP 429

When this class encounters HTTP 429 (rate limited on Helix API), it just throws a generic error:

Something went wrong during the request! Please try again later

Instead, it should throw an error message indicating that the user probably needs to set up rate limiting in the API client (I assumed that not providing a rate limited meant that it just defaulted to an implementation that uses the API headers, rather than no rate limiting at all).

Not Compatible with Visual Basic

From @mbfan on April 27, 2018 17:22

Hello,
please consider rewriting the Code to remove all duplication of Members. Visual Basic ignores upper and lower case, and i can't use any method cause there is (for example) a "v5" and a "V5", which are the same to VB.
With kind regards,
Nico

Copied from original issue: TwitchLib/TwitchLib#394

ITwitchAPI is not mockable

I am looking forward to using TwitchLib.Api for a project I am currently working on, but it does look like ITwitchAPI can't correctly be mocked and used in unit tests.

Having ITwitchAPI define concrete type as properties makes it impossible to mock the underlying implementation.

Am I missing something here? Are there plans to make it more unit-test friendly?

V5.Users.CheckUserSubscriptionByChannelAsync throws HttpRequestException when token is not from user

When calling the V5.Users.CheckUserSubscriptionByChannelAsync endpoint, and the token is not from the user, but instead from the channel owner, a HttpRequestException is thrown.

The cause of this is that this specific endpoint is meant for the User to get information about a subscription to a channel, not the other way around.

The response from the API on Twitch's side is a 403 (Forbidden) with the message: "Cannot view user subscription's channel of another user."

Since the HandleWebException in the TwitchHttpClient does not handle 403 return codes, a generic HttpRequestException is thrown instead.
The user gets this error message without any other information on what's going wrong and has no access to the message provided by Twitch.

NotPartneredException on Follower Service (v1.1.0)

I'm getting a "The resource you requested is only available to channels that have been partnered by Twitch." if I try to get a Followers Name on Follower Service.

My Code:

foreach (var follower in e.NewFollowers)
{
     if (follower == null)
     {
         continue;
     }

     // Getting User by ID
     var getFollowerName = await TwitchService.TwitchAPIClient.V5.Users.GetUserByIDAsync(follower.FromUserId); 
     // Crashes on this one with the TwitchLib.Api.Core.Exceptions.NotPartneredException

}

WebException: The remote name could not be resolved: 'api.twitch.tv'

Lately I have been leaving my bot running in debug mode because it tends to crash randomly, and this error has showed up twice now:

System.Net.Http.HttpRequestException
HResult=0x80131509
Message=An error occurred while sending the request.
Source=mscorlib
StackTrace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at TwitchLib.Api.Core.Internal.TwitchHttpClientHandler.d__2.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.Http.HttpClient.d__58.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at TwitchLib.Api.Core.HttpCallHandlers.TwitchHttpClient.GeneralRequest(String url, String method, String payload, ApiVersion api, String clientId, String accessToken)
at TwitchLib.Api.Core.ApiBase.<>c__DisplayClass13_01.<TwitchGetGenericAsync>b__1() at System.Threading.Tasks.Task1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at TwitchLib.Api.Core.ApiBase.<>c__DisplayClass13_0`1.<b__0>d.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at TwitchLib.Api.Services.LiveStreamMonitorService.d__30.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at TwitchLib.Api.Services.LiveStreamMonitorService.d__26.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at TwitchLib.Api.Services.LiveStreamMonitorService.d__27.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at TwitchLib.Api.Services.Core.ServiceTimer.d__6.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.b__6_1(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Inner Exception 1:
WebException: The remote name could not be resolved: 'api.twitch.tv'

Let me know if you need any more information.

[Suggestion] Add a summary to all endpoints

Sometimes it can be quite unclear what an endpoint in the API does exactly.
Along with that, it can throw unexpected exceptions which aren't documented anywhere.
Next to that, even the parameter names aren't quite clear from time to time.

So my suggestion is to start adding summaries to at least all future added endpoints (Helix) and try to add a summary to all current Helix endpoints which are already created.
For V5 endpoints, it would be nice, but since it's a bit depreciated and it should be removed at the end of the year), it might not be worth adding them to those endpoints.

An example of a summary would be:

/// <summary>
/// <see href="https://dev.twitch.tv/docs/api/reference/#replace-stream-tags">Replace Stream Tags</see>
/// </summary>
/// <exception cref="ArgumentNullException">When the <paramref name="broadcasterId"/> is null.</exception>
/// <exception cref="ArgumentException">When the amount of tags in <paramref name="tagIds"/> is more than 5.</exception>
/// <param name="broadcasterId">ID of the stream for which tags are to be replaced.</param>
/// <param name="tagIds">IDs of tags to be applied to the stream.</param>
/// <param name="accessToken">An accessToken to use for this specific request.</param>

Preferably it would also have the methods which can be thrown internally, such as BadScopeException, BadGatewayException, InternalServerErrorException, etc. Since it's possible that this method throws those errors and a user should know that he/she needs to handle them if such a thing happens for whatever reason.

OnStreamOffline Long Delay

I set the polling Interval to 30 seconds and it works perfectly for OnStreamOnline but it takes 5-10 minutes after the stream has ended for OnStreamOffline to be triggered.

Some of the data in the response was lost.

I make a request through "api.V5.Games.GetTopGamesAsync(...)", part of the data in the class "TwitchLib.Api.V5.Models.Games.Game" disappears (I get "id == 0" and "viewers == 0").

I checked the response format on the website using the link below and in the TwitchLib.Api code. The response format may have changed (the id was renamed _id, and the viewers were completely removed).

https://dev.twitch.tv/docs/v5/reference/games/

Can you confirm the problem?

LiveStreamMonitor exception (unhandled internally)

Hello, the following happened after running the LiveStreamMonitor service for possibly a few days, im not entirely sure on the time. Surprisingly that somehow crashed my application.

Some usage context if that helps: I have a timer that runs every minute and calls "SetChannelsById"; I am only calling UpdateLiveStreamersAsync once, at the application start-up; there has been only 1 twitch channel in the list all along.

2020-10-22T00:21:55.639802057Z Unhandled exception. System.Net.Http.HttpRequestException: An error occurred while sending the request.
2020-10-22T00:21:55.639865762Z ---> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer.
2020-10-22T00:21:55.639922366Z ---> System.Net.Sockets.SocketException (104): Connection reset by peer
2020-10-22T00:21:55.639947168Z --- End of inner exception stack trace ---
2020-10-22T00:21:55.639983171Z at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
2020-10-22T00:21:55.639997172Z at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
2020-10-22T00:21:55.640040775Z at System.Net.Security.SslStream.g__InternalFillBufferAsync|215_0[TReadAdapter](TReadAdapter adap, ValueTask1 task, Int32 min, Int32 initial) 2020-10-22T00:21:55.640055377Z at System.Net.Security.SslStream.ReadAsyncInternal[TReadAdapter](TReadAdapter adapter, Memory1 buffer)
2020-10-22T00:21:55.640088879Z at System.Net.Http.HttpConnection.FillAsync()
2020-10-22T00:21:55.640102580Z at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean foldedHeadersAllowed)
2020-10-22T00:21:55.640144684Z at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
2020-10-22T00:21:55.640159085Z --- End of inner exception stack trace ---
2020-10-22T00:21:55.640190987Z at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
2020-10-22T00:21:55.640204588Z at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
2020-10-22T00:21:55.656753594Z at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
2020-10-22T00:21:55.656772195Z at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2020-10-22T00:21:55.656777496Z at TwitchLib.Api.Core.Internal.TwitchHttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2020-10-22T00:21:55.656781596Z at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) 2020-10-22T00:21:55.656787597Z at TwitchLib.Api.Core.HttpCallHandlers.TwitchHttpClient.GeneralRequest(String url, String method, String payload, ApiVersion api, String clientId, String accessToken) 2020-10-22T00:21:55.656791797Z at TwitchLib.Api.Core.ApiBase.<>c__DisplayClass14_01.b__1()
2020-10-22T00:21:55.656796097Z at System.Threading.Tasks.Task1.InnerInvoke() 2020-10-22T00:21:55.656800098Z at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) 2020-10-22T00:21:55.656812198Z --- End of stack trace from previous location where exception was thrown --- 2020-10-22T00:21:55.656815699Z at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) 2020-10-22T00:21:55.656830000Z --- End of stack trace from previous location where exception was thrown --- 2020-10-22T00:21:55.656833700Z at TwitchLib.Api.Core.ApiBase.<>c__DisplayClass14_01.<b__0>d.MoveNext()
2020-10-22T00:21:55.656837801Z --- End of stack trace from previous location where exception was thrown ---
2020-10-22T00:21:55.656841101Z at TwitchLib.Api.Services.LiveStreamMonitorService.GetLiveStreamersAsync()
2020-10-22T00:21:55.656844601Z at TwitchLib.Api.Services.LiveStreamMonitorService.UpdateLiveStreamersAsync(Boolean callEvents)
2020-10-22T00:21:55.656848001Z at TwitchLib.Api.Services.LiveStreamMonitorService.OnServiceTimerTick()
2020-10-22T00:21:55.656851402Z at TwitchLib.Api.Services.Core.ServiceTimer.TimerElapsedAsync(Object sender, ElapsedEventArgs e)
2020-10-22T00:21:55.656854802Z at System.Threading.Tasks.Task.<>c.b__139_1(Object state)
2020-10-22T00:21:55.656858502Z at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi)
2020-10-22T00:21:55.656862202Z at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action`1 callback, TState& state)
2020-10-22T00:21:55.656866003Z at System.Threading.QueueUserWorkItemCallback.Execute()
2020-10-22T00:21:55.656869503Z at System.Threading.ThreadPoolWorkQueue.Dispatch()

Please consider adding a CancellationToken as parameter for async methods

From @niklr on April 12, 2018 10:1

Is it currently possible to cancel a pending async method? What happens if Twitch is down: will the sync/async methods run forever or cancel/timeout after a specific time?

Please consider adding a CancellationToken as parameter for async methods. Additionally, consider the possibility to specify a number of milliseconds to wait before requests time out.

Copied from original issue: TwitchLib/TwitchLib#389

Twitch OAuth2 code flow

Note: I'm not sure if the API repo is the right place for this, but I see you have other v5 auth methods so I'll add it here.

Any plan on adding the OAuth Code Flow endpoints to the library? This would be very helpful. You seem to have something similar in v5.Auth for refreshing tokens; it would be nice to see "GetAuthorizationUrl" and "AuthorizeCode" methods in there too.

Here's what I'm having to do now:

public static async Task<string> AuthorizeCode(string code, string clientId, string secret, string redirectUrl, HttpClient client, CancellationToken? cancellationToken = null)
{
	var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post,
		"https://id.twitch.tv/oauth2/token?" +
		$"client_id={clientId}&" +
		$"client_secret={HttpUtility.UrlEncode(secret)}&" +
		$"code={code}&" +
		"grant_type=authorization_code&" +
		$"redirect_uri={HttpUtility.UrlEncode(redirectUrl)}");

	var twitchTokenResponse = cancellationToken != null
		? await client.SendAsync(httpRequestMessage, cancellationToken.Value)
		: await client.SendAsync(httpRequestMessage);

	var responseString = await twitchTokenResponse.Content.ReadAsStringAsync();
	return
		twitchTokenResponse.IsSuccessStatusCode
			? JObject.Parse(responseString).GetValue("access_token").Value<string>()
			: null;
}

Hope you'll consider it!

Server based access token are generated on every request

Currently when using server based access tokens (client_credentials flow) a new access token is created for every api call.
This creates a lot of unneccessary requests and delay.

Instead the expiration time should be stored and a new access token only requested when it is near that expiration time.

V5.Users.CheckUserSubscriptionByChannelAsync response User property null

When getting a successful response from V5.Users.CheckUserSubscriptionByChannelAsync, the .User property from the "Subscription" response is null.

The reason: This endpoint has a Channel object instead of a User object in the response instead.
See the difference between:

The same response class is used, hence the .User property is null.

V5.Users.CheckUserSubscriptionByChannelAsync and V5.Channels.CheckChannelSubscriptionByUserAsync throw BadResourceException when user is not subscribed

Both the V5.Users.CheckUserSubscriptionByChannelAsync and V5.Channels.CheckChannelSubscriptionByUserAsync throw a BadResourceException when the provided user is not subscribed to the target channel.

The reason: Twitch returns a 404 with a message "[channel/user name] has no subscriptions to [channel/user name]" when the subscription cannot be found in both cases.

See the example responses if the User is Not Subscribed to the Channel:

The fact that TwitchLib throws a BadResourceException is unwanted, since the "twitch api resource can be found". It's just that there is no subscription.

This is very unclear, and there is no way of knowing what the actual problem is, since the message in the response cannot be obtained from the BadResourceException.

Proxy in API

Hello!

Is there any option to set proxy in API object? If it is, can you give me example how I can set it. If not please add this feature. Maybe like param in API object constructor, or in Settings param.

Undocumented.GetChatUserAsync returns null Badges

The Undocumented.GetChatUserAsync method returns ChatUserResponse, which has a Badges property of type KeyValuePair<string,string>, but that's not the structure returned from the API Call. An array of models in this structure could handle the badge data that is returned.

public class Badge
{
    public string id { get; set; }
    public string version { get; set; }
}

Add Get Id Examples

Many seem to ask, so good to have.

//V5
var user = await api.V5.Users.GetUserByNameAsync("ChannelName");

Error Capturing Question

Is there a "preferred way" to capture and/or ignore errors thrown by the Library? I am getting a 502 error from Twitch every now and then, but would like it to try again at the specified interval.

An unhandled exception of type 'TwitchLib.Api.Core.Exceptions.BadGatewayException' occurred in System.Private.CoreLib.dll: 'The API answered with a 502 Bad Gateway. Please retry your request'
Stack trace:
 >   at TwitchLib.Api.Core.HttpCallHandlers.TwitchHttpClient.HandleWebException(HttpResponseMessage errorResp)
 >   at TwitchLib.Api.Core.HttpCallHandlers.TwitchHttpClient.GeneralRequest(String url, String method, String payload, ApiVersion api, String clientId, String accessToken)
 >   at TwitchLib.Api.Core.ApiBase.GenerateServerBasedAccessToken()
 >   at TwitchLib.Api.Core.ApiBase.GetAccessToken(String accessToken)
 >   at TwitchLib.Api.Core.ApiBase.TwitchGetGenericAsync[T](String resource, ApiVersion api, List`1 getParams, String accessToken, String clientId, String customBase)
 >   at TwitchLib.Api.Helix.Streams.GetStreamsAsync(String after, List`1 communityIds, Int32 first, List`1 gameIds, List`1 languages, String type, List`1 userIds, List`1 userLogins)
 >   at TwitchLib.Api.Services.Core.LiveStreamMonitor.IdBasedMonitor.GetStreamsAsync(List`1 channels)
 >   at TwitchLib.Api.Services.LiveStreamMonitorService.<GetLiveStreamersAsync>d__30.MoveNext()
 >   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 >   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 >   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 >   at TwitchLib.Api.Services.LiveStreamMonitorService.<UpdateLiveStreamersAsync>d__26.MoveNext()
 >   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 >   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 >   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 >   at TwitchLib.Api.Services.LiveStreamMonitorService.<OnServiceTimerTick>d__27.MoveNext()
 >   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 >   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 >   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 >   at TwitchLib.Api.Services.Core.ServiceTimer.<TimerElapsedAsync>d__6.MoveNext()
 >   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 >   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
 >   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
 >   at System.Threading.ThreadPoolWorkQueue.Dispatch()

GetExtensionTransactionsResponse Does Not Include Pagination Cursor

The TwitchLib.Api.Helix.Models.Extensions.Transactions.GetExtensionTransactionsResponse model does not include the pagination object that contains the cursor. This makes it impossible to paginate records.

Also consider renaming CreatedClips to Data to be consistent with the response content.

Making the Api library testable

So the Api is not really testable at the moment due to its dependency on HttpClient (>2.0) and WebRequest (<2.0)

Therefore I propose the following:-

  1. Break out the actual calls made into a different class
  2. create an interface
  3. profit

With the aim of making the Api more DI friendly this would mean a new constructor value in which a "HttpCallHandler" can be injected

GetUserActiveExtensions - missing parameter

Hi there!

According to the docs, I can ask the extensions for a specific user by supplying the user_id:

image

Unfortunately, TwitchLib doesn't seem to support this, the relevant code seems to be here

        public Task<GetUserActiveExtensionsResponse> GetUserActiveExtensionsAsync(string authToken = null)
        {
            return TwitchGetGenericAsync<GetUserActiveExtensionsResponse>("/users/extensions", ApiVersion.Helix, accessToken: authToken);
        }

I think I'll try a PR, as I need that endpoint, but still creating this issue just in case.

Unhandled exception in LiveStreamMonitorService

CoreCLR Version: 4.6.27129.4
Description: The process was terminated due to an unhandled exception.
Exception Info: TwitchLib.Api.Core.Exceptions.InternalServerErrorException: The API answered with a 500 Internal Server Error. Please retry your request
at TwitchLib.Api.Core.HttpCallHandlers.TwitchHttpClient.HandleWebException(HttpResponseMessage errorResp)
at TwitchLib.Api.Core.HttpCallHandlers.TwitchHttpClient.GeneralRequest(String url, String method, String payload, ApiVersion api, String clientId, String accessToken)
at TwitchLib.Api.Core.ApiBase.<>c__DisplayClass13_01.<TwitchGetGenericAsync>b__1() at System.Threading.Tasks.Task1.InnerInvoke()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
--- End of stack trace from previous location where exception was thrown ---
at TwitchLib.Api.Core.ApiBase.<>c__DisplayClass13_0`1.<b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at TwitchLib.Api.Services.LiveStreamMonitorService.GetLiveStreamersAsync()
at TwitchLib.Api.Services.LiveStreamMonitorService.UpdateLiveStreamersAsync(Boolean callEvents)
at TwitchLib.Api.Services.LiveStreamMonitorService.OnServiceTimerTick()
at TwitchLib.Api.Services.Core.ServiceTimer.TimerElapsedAsync(Object sender, ElapsedEventArgs e)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.ThreadPoolWorkQueue.Dispatch()

I believe exception escapes here

await _serviceTimerTickAsyncCallback();

From MSDN

The Timer component catches and suppresses all exceptions thrown by event handlers for the Elapsed event. This behavior is subject to change in future releases of the .NET Framework. Note, however, that this is not true of event handlers that execute asynchronously and include the await operator (in C#) or the Await operator (in Visual Basic). Exceptions thrown in these event handlers are propagated back to the calling thread, as the following example illustrates.

Missing AuthScopes at PingResponse

Working with this library I've found I can't use the Third Party AuthorizationFlow with Channel_Editor scope. Maybe it's due to the missing of this scope at TwitchLib.Api/TwitchLib.Api/ThirdParty/AuthorizationFlow/PingResponse.cs - StringToScope method.

private AuthScopes StringToScope(string scope)
        {
            switch (scope)
            {
                case "user_read":
                    return AuthScopes.User_Read;
                case "user_blocks_edit":
                    return AuthScopes.User_Blocks_Edit;
                case "user_blocks_read":
                    return AuthScopes.User_Blocks_Read;
                case "user_follows_edit":
                    return AuthScopes.User_Follows_Edit;
                case "channel_read":
                    return AuthScopes.Channel_Read;
                case "channel_commercial":
                    return AuthScopes.Channel_Commercial;
                case "channel_stream":
                    return AuthScopes.Channel_Subscriptions;
                case "channel_subscriptions":
                    return AuthScopes.Channel_Subscriptions;
                case "user_subscriptions":
                    return AuthScopes.User_Subscriptions;
                case "channel_check_subscription":
                    return AuthScopes.Channel_Check_Subscription;
                case "chat_login":
                    return AuthScopes.Chat_Login;
                case "channel_feed_read":
                    return AuthScopes.Channel_Feed_Read;
                case "channel_feed_edit":
                    return AuthScopes.Channel_Feed_Edit;
                case "collections_edit":
                    return AuthScopes.Collections_Edit;
                case "communities_edit":
                    return AuthScopes.Communities_Edit;
                case "communities_moderate":
                    return AuthScopes.Communities_Moderate;
                case "viewing_activity_read":
                    return AuthScopes.Viewing_Activity_Read;
                case "user:edit":
                    return AuthScopes.Helix_User_Edit;
                case "user:read:email":
                    return AuthScopes.Helix_User_Read_Email;
                case "clips:edit":
                    return AuthScopes.Helix_Clips_Edit;
                case "analytics:read:games":
                    return AuthScopes.Helix_Analytics_Read_Games;
                case "bits:read":
                    return AuthScopes.Helix_Bits_Read;
                default:
                    throw new Exception("Unknown scope");
            }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.