// See https://dev.twitter.com/docs/auth/authorizing-request
        public async Task <Boolean> UpdateStatus(String status) // a.k.a. tweet
        {
            IsTweeting = true;
            Status     = "Tweeting";
            var header = new TwitterRtDictionary();

            header.Add("oauth_consumer_key", _consumerKey);
            header.Add("oauth_nonce", GenerateNonce());
            header.Add("oauth_signature_method", _signatureMethod);
            header.Add("oauth_timestamp", GenerateSinceEpoch());
            header.Add("oauth_token", OauthToken);
            header.Add("oauth_version", _oauthVersion);
            var request = new TwitterRtDictionary();

            request.Add("status", Uri.EscapeDataString(status));
            var response = await PostData(_updateStatusUrl, header, request);

            IsTweeting = false;

            if (response.Status == TwitterRtPostResults.EStatus.Success)
            {
                Status = status;
                return(true);
            }
            else
            {
                Status = response.Description;
                return(false);
            }
        }
 public void Add(TwitterRtDictionary src)
 {
     if (src != null)
     {
         foreach (var kvp in src)
         {
             Add(kvp.Key, kvp.Value);
         }
     }
 }
        // Step 1: Obtaining a request token
        async Task <TwitterRtPostResults> Step1()
        {
            var header = new TwitterRtDictionary();

            header.Add("oauth_callback", Uri.EscapeDataString(_callbackUrl));
            header.Add("oauth_consumer_key", _consumerKey);
            header.Add("oauth_nonce", GenerateNonce());
            header.Add("oauth_signature_method", _signatureMethod);
            header.Add("oauth_timestamp", GenerateSinceEpoch());
            header.Add("oauth_version", _oauthVersion);
            return(await PostData(_requestTokenUrl, header)); // should contain oauth_token, oauth_token_secret, and oauth_callback_confirmed
        }
        // Step 3: Converting the request token to an access token
        async Task <TwitterRtPostResults> Step3(String oauthToken, String oauthVerifier)
        {
            var header = new TwitterRtDictionary();

            header.Add("oauth_consumer_key", _consumerKey);
            header.Add("oauth_nonce", GenerateNonce());
            header.Add("oauth_signature_method", _signatureMethod);
            header.Add("oauth_timestamp", GenerateSinceEpoch());
            header.Add("oauth_token", oauthToken);
            header.Add("oauth_version", _oauthVersion);
            var request = new TwitterRtDictionary();

            request.Add("oauth_verifier", Uri.EscapeDataString(oauthVerifier));
            return(await PostData(_accessTokenUrl, header, request));  // should contain oauth_token, oauth_token_secret, user_id, and screen_name
        }
        async Task <TwitterRtPostResults> PostData(String url, TwitterRtDictionary headerDictionary, TwitterRtDictionary requestDictionary = null)
        {
            // See https://dev.twitter.com/docs/auth/creating-signature
            var combinedDictionaries = new TwitterRtDictionary(headerDictionary);

            combinedDictionaries.Add(requestDictionary);
            var signatureBase   = "POST&" + Uri.EscapeDataString(url) + "&" + Uri.EscapeDataString(combinedDictionaries.ToStringA());
            var keyMaterial     = CryptographicBuffer.ConvertStringToBinary(_consumerSecret + "&" + OauthTokenSecret, BinaryStringEncoding.Utf8);
            var algorithm       = MacAlgorithmProvider.OpenAlgorithm("HMAC_SHA1");
            var key             = algorithm.CreateKey(keyMaterial);
            var dataToBeSigned  = CryptographicBuffer.ConvertStringToBinary(signatureBase, BinaryStringEncoding.Utf8);
            var signatureBuffer = CryptographicEngine.Sign(key, dataToBeSigned);
            var signature       = CryptographicBuffer.EncodeToBase64String(signatureBuffer);
            var headers         = "OAuth " + headerDictionary.ToStringQ() + ", oauth_signature=\"" + Uri.EscapeDataString(signature) + "\"";

            return(await PostData(url, headers, (requestDictionary == null)?String.Empty : requestDictionary.ToString()));
        }
 public TwitterRtDictionary(TwitterRtDictionary src)
 {
     Add(src);
 }