예제 #1
0
        public void Authenticate( OauthAuthorization authorization)
        {
            logger.Debug("Authenticating twitter client");
            this.authorization = authorization;

            string encodedKey = EncodeConsumerKeyAndSecret(authorization.ConsumerKey,authorization.ConsumerSecret);

            // create request
            var keyValuePair = new KeyValuePair<string, string>("grant_type", "client_credentials");
            HttpContent httpContent = new FormUrlEncodedContent(new Collection<KeyValuePair<string, string>>(){keyValuePair});
            httpContent.Headers.ContentType.CharSet = "UTF-8";
            this._client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip");
            this._client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", encodedKey);

            // post request
            HttpResponseMessage postAsync = _client.PostAsync("/oauth2/token", httpContent).Result;
            HandleErrors(postAsync);

            // Get access token
            Stream readAsStringAsync = postAsync.Content.ReadAsStreamAsync().Result;
            string json = Decompress(readAsStringAsync);
            this._accessToken = JsonConvert.DeserializeObject<AccessToken>(json);

            this._client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(this._accessToken.token_type, this._accessToken.access_token);

            logger.Debug("Authenticated");
        }
예제 #2
0
        private static OauthAuthorization CurrentOAuth()
        {
            string consumerkey =  Settings.Default.key;
            string consumersecret = Settings.Default.secret;
            string accessToken = Settings.Default.accessToken;
            string accessTokenSecret = Settings.Default.accessTokenSecret;

            var oauthAuthorization = new OauthAuthorization(consumerkey, consumersecret,
                                                            accessToken, accessTokenSecret);
            return oauthAuthorization;
        }
예제 #3
0
        public OAuthParameters(OauthAuthorization authorization, string resourceUrl, List<KeyValuePair<string, string>> postBody, List<KeyValuePair<string, string>> urlParameters)
        {
            this.Authorization = authorization;
            this.PostBody = postBody;
            this.ResourceUrl = resourceUrl;
            this.UrlParameters = urlParameters;

            // Defualt values
            this.OAuthVersion = "1.0";
            this.SignatureMethod = "HMAC-SHA1";
            this.Nonce = Convert.ToBase64String(
                new ASCIIEncoding().GetBytes(
                    DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture)));
            this.TimeStamp = CreateOauthTimeStap();
        }
        private static OAuthParameters TestOAuthParameters()
        {
            KeyValuePair<string, string> body = new KeyValuePair<string, string>(
                "status", "Hello Ladies + Gentlemen, a signed OAuth request!");
            KeyValuePair<string, string> urlParam = new KeyValuePair<string, string>("include_entities", "true");

            // sample from twitter
            OauthAuthorization oauthAuthorization = new OauthAuthorization(
                "xvz1evFS4wEEPTGEFPHBog", "kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw", "370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb", "LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE");

            OAuthParameters oAuthParameters = new OAuthParameters(
                oauthAuthorization,
                "https://api.twitter.com/1/statuses/update.json",
                new List<KeyValuePair<string, string>>() { body },
                new List<KeyValuePair<string, string>>() { urlParam });

            // override with sample data.
            oAuthParameters.TimeStamp = "1318622958";
            oAuthParameters.Nonce = "kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg";
            return oAuthParameters;
        }
예제 #5
0
 public OAuthParameters(OauthAuthorization authorization, string resourceUrl, List<KeyValuePair<string, string>> postBody)
     : this(authorization, resourceUrl, postBody, new List<KeyValuePair<string, string>>())
 {
 }
예제 #6
0
 public Retweeter(OauthAuthorization authorization)
 {
     this.client = new TwitterClient();
     this.client.Authenticate(authorization);
 }
 public TwitterStreamingClient(OauthAuthorization authorization, IProcessor processor)
 {
     this.authorization = authorization;
     this.processor = processor;
 }