public TwitterOAuthRequestConstructor(Uri requestUri, TwitterOAuthTokens tokens, string method = "GET")
        {
            Verb = method;

            RequestUriWithoutQuery = new Uri(requestUri.AbsolutaSinQuery());

            if (!string.IsNullOrEmpty(requestUri.Query))
            {
                QueryParams = requestUri.CogerQueryParametros()
                              .Select(p => new OAuthParametro(p.Key, Uri.UnescapeDataString(p.Value)))
                              .ToList();
            }
            else
            {
                QueryParams = new List <OAuthParametro>();
            }

            EncodedRequestUri = GetEncodedUri(requestUri, QueryParams);

            Version         = new OAuthParametro("oauth_version", "1.0");
            Nonce           = new OAuthParametro("oauth_nonce", GenerarNonce());
            Timestamp       = new OAuthParametro("oauth_timestamp", GenerarTiempoLapso());
            SignatureMethod = new OAuthParametro("oauth_signature_method", "HMAC-SHA1");
            ConsumerKey     = new OAuthParametro("oauth_consumer_key", tokens.ConsumerKey);
            ConsumerSecret  = new OAuthParametro("oauth_consumer_secret", tokens.ConsumerSecret);
            Token           = new OAuthParametro("oauth_token", tokens.AccessToken);
            TokenSecret     = new OAuthParametro("oauth_token_secret", tokens.AccessTokenSecret);
            TokenCallback   = new OAuthParametro("oauth_callback", "https://pepeizqapps.com/");
        }
Exemplo n.º 2
0
        public async Task EjecutarGetStreamAsync(Uri requestUri, TwitterOAuthTokens tokens, TwitterStreamLlamadas.RawJsonLlamada llamada)
        {
            using (var request = new HttpRequestMessage(HttpMethod.Get, requestUri))
            {
                var requestBuilder = new TwitterOAuthRequestConstructor(requestUri, tokens);

                request.Headers.Authorization = AuthenticationHeaderValue.Parse(requestBuilder.AuthorizationHeader);

                using (var response = await cliente.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false))
                {
                    var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

                    using (var reader = new StreamReader(responseStream))
                    {
                        while (!_abort && !reader.EndOfStream)
                        {
                            var result = reader.ReadLine();

                            if (!string.IsNullOrEmpty(result))
                            {
                                llamada?.Invoke(result);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public async Task <string> EjecutarPostAsync(Uri requestUri, TwitterOAuthTokens tokens)
        {
            using (var request = new HttpRequestMessage(HttpMethod.Post, requestUri))
            {
                var requestBuilder = new TwitterOAuthRequestConstructor(requestUri, tokens, "POST");

                request.Headers.Authorization = AuthenticationHeaderValue.Parse(requestBuilder.AuthorizationHeader);

                using (var response = await cliente.SendAsync(request).ConfigureAwait(false))
                {
                    return(ProcesarErrores(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
                }
            }
        }
Exemplo n.º 4
0
        public async Task <string> EjecutarPostMultipartAsync(Uri requestUri, TwitterOAuthTokens tokens, string boundary, byte[] content)
        {
            JToken mediaId = null;

            try
            {
                using (var multipartFormDataContent = new MultipartFormDataContent(boundary))
                {
                    using (var byteContent = new ByteArrayContent(content))
                    {
                        multipartFormDataContent.Add(byteContent, "media");

                        using (var request = new HttpRequestMessage(HttpMethod.Post, requestUri))
                        {
                            var requestBuilder = new TwitterOAuthRequestConstructor(requestUri, tokens, "POST");

                            request.Headers.Authorization = AuthenticationHeaderValue.Parse(requestBuilder.AuthorizationHeader);

                            request.Content = multipartFormDataContent;

                            using (var response = await cliente.SendAsync(request).ConfigureAwait(false))
                            {
                                string jsonResultado = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                                JObject jObj = JObject.Parse(jsonResultado);
                                mediaId = jObj["media_id_string"];
                            }
                        }
                    }
                }
            }
            catch (ObjectDisposedException)
            {
                // http://stackoverflow.com/questions/39109060/httpmultipartformdatacontent-dispose-throws-objectdisposedexception
            }

            return(mediaId.ToString());
        }