Ejemplo n.º 1
0
        public static StreamData ParseCmplexJSON(string uncleanJson)
        {
            StreamData cleanJson = null;

            try
            {
                JToken token = JObject.Parse(uncleanJson);

                cleanJson = JsonConvert.DeserializeObject <StreamData>(token.SelectToken("data").ToString());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(cleanJson);
        }
        private async Task <StreamData> GetInternalAsync(HttpMethod method, string brToken, string apiURL, int?timeOutInMinute = null)
        {
            const string url = "https://api.twitter.com/2/tweets/sample/stream";

            StreamData limitedJson = null;

            _httpClient.DefaultRequestHeaders.Clear();
            _httpClient.DefaultRequestHeaders.Add("Authorization", ValidateToken(brToken));
            HttpResponseMessage response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);

            Stream streamToReadFrom = await response.Content.ReadAsStreamAsync();

            var bytes     = new byte[2084];
            var bytesread = streamToReadFrom.Read(bytes, 0, 2084);

            streamToReadFrom.Close();
            limitedJson = Utility.ParseCmplexJSON(Encoding.UTF8.GetString(bytes).ToString());

            return(limitedJson);
        }