Пример #1
0
        // 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);
            }
        }
Пример #2
0
 public void Add(TwitterRtDictionary src)
 {
     if (src != null)
     {
         foreach (var kvp in src)
         {
             Add(kvp.Key, kvp.Value);
         }
     }
 }
Пример #3
0
        // 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
        }
Пример #4
0
        // 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
        }
Пример #5
0
        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()));
        }
Пример #6
0
        public async Task <string> GetTimeline()
        {
            Status = "Getting timeline";
            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();
            var response = await GetData(_getTimelineUrl, header, request);

            if (response.Dictionary != null)
            {
                return(response.Dictionary["timeline"]);
            }

            return(string.Empty);
        }
Пример #7
0
 public TwitterRtDictionary(TwitterRtDictionary src)
 {
     Add(src);
 }