FlickrNet.Twitter.OAuthCalculateSignatureForCalls C# (CSharp) Méthode

OAuthCalculateSignatureForCalls() public méthode

public OAuthCalculateSignatureForCalls ( string method, string url, string>.Dictionary parameters, string tokenSecret ) : string
method string
url string
parameters string>.Dictionary
tokenSecret string
Résultat string
        public string OAuthCalculateSignatureForCalls(string method, string url, Dictionary<string, string> parameters, string tokenSecret)
        {
            string baseString = "";
            string key = ApiSecret + "&" + tokenSecret;
            byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(key);


            var sorted = parameters.OrderBy(p => p.Key);


            StringBuilder sb = new StringBuilder();
            foreach (KeyValuePair<string, string> pair in sorted)
            {

                if (pair.Key.StartsWith("method"))
                {

                }
                else
                {
                    sb.Append(pair.Key);
                    sb.Append("=");
                    sb.Append(UtilityMethods.EscapeOAuthString(pair.Value));
                    sb.Append("&");
                }

            }

            sb.Remove(sb.Length - 1, 1);

            baseString = method + "&" + UtilityMethods.EscapeOAuthString(url) + "&" + UtilityMethods.EscapeOAuthString(sb.ToString());
            //baseString = method + "&" + UtilityMethods.EscapeOAuthString(url);



            //System.Security.Cryptography.HMACSHA1 sha1 = new System.Security.Cryptography.HMACSHA1(keyBytes);


            //byte[] hashBytes = sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(baseString));

            //string hash = Convert.ToBase64String(hashBytes);
            string hash = UtilityMethods.Sha1Encrypt(baseString, key);

            Debug.WriteLine("key  = " + key);
            Debug.WriteLine("base = " + baseString);
            Debug.WriteLine("sig  = " + hash);

            return hash;
        }

Usage Example

Exemple #1
0
        private async static Task<FlickrResult<string>> GetDataResponseOAuthAsync(Twitter flickr, string method, string baseUrl, Dictionary<string, string> parameters)
        {
            if (parameters.ContainsKey("api_key")) parameters.Remove("api_key");

            if (parameters.ContainsKey("api_sig")) parameters.Remove("api_sig");

            if (!String.IsNullOrEmpty(flickr.OAuthAccessToken) && !parameters.ContainsKey("oauth_token"))
            {
                parameters.Add("oauth_token", flickr.OAuthAccessToken);
            }
            if (!String.IsNullOrEmpty(flickr.OAuthAccessTokenSecret) && !parameters.ContainsKey("oauth_signature"))
            {
                string sig = flickr.OAuthCalculateSignatureForCalls(method, baseUrl, parameters, flickr.OAuthAccessTokenSecret);
                parameters.Add("oauth_signature", sig);
            }

            string data = OAuthCalculatePostData(parameters);

            string authHeader = OAuthCalculateAuthHeader(parameters);


            baseUrl = baseUrl.Split("?".ToCharArray())[0];

            if (method == "GET") return await DownloadDataAsync(method, baseUrl, data, GetContentType, authHeader);
            else return await DownloadDataAsync(method, baseUrl, data, PostContentType, authHeader);

        }
All Usage Examples Of FlickrNet.Twitter::OAuthCalculateSignatureForCalls