diff --git a/src/BirdsiteLive.Twitter/Tools/TwitterAuthenticationInitializer.cs b/src/BirdsiteLive.Twitter/Tools/TwitterAuthenticationInitializer.cs index ac2bd5b..6e4c7c0 100644 --- a/src/BirdsiteLive.Twitter/Tools/TwitterAuthenticationInitializer.cs +++ b/src/BirdsiteLive.Twitter/Tools/TwitterAuthenticationInitializer.cs @@ -1,6 +1,6 @@ using System; using System.Threading; -using System.Timers; +using System.Collections.Generic; using System.Threading.Tasks; using BirdsiteLive.Common.Settings; using Microsoft.Extensions.Logging; @@ -12,8 +12,6 @@ namespace BirdsiteLive.Twitter.Tools { public interface ITwitterAuthenticationInitializer { - String BearerToken { get; } - String GuestToken { get; } Task EnsureAuthenticationIsInitialized(); Task MakeHttpClient(); } @@ -24,14 +22,12 @@ namespace BirdsiteLive.Twitter.Tools private static bool _initialized; private static System.Timers.Timer aTimer; private readonly HttpClient _httpClient = new HttpClient(); - private HttpClient _twitterClient; - private String _token; + private List _twitterClients = new List(); + private List _tokens = new List(); + static Random rnd = new Random(); public String BearerToken { get { return "AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw"; } } - public String GuestToken { - get { return _token; } - } #region Ctor public TwitterAuthenticationInitializer(ILogger logger) @@ -63,7 +59,10 @@ namespace BirdsiteLive.Twitter.Tools client.DefaultRequestHeaders.TryAddWithoutValidation("Referer", "https://twitter.com/"); client.DefaultRequestHeaders.TryAddWithoutValidation("x-twitter-active-user", "yes"); - _twitterClient = client; + _twitterClients.Add(client); + + if (_twitterClients.Count > 10) + _twitterClients.RemoveAt(0); } private async Task<(string, string)> GetCred() @@ -104,9 +103,10 @@ namespace BirdsiteLive.Twitter.Tools public async Task MakeHttpClient() { - if (_twitterClient == null) + if (_twitterClients.Count < 3) await RefreshCred(); - return _twitterClient; + int r = rnd.Next(_twitterClients.Count); + return _twitterClients[r]; } } } \ No newline at end of file