当前位置: 首页>>代码示例>>C#>>正文


C# Flickr.OAuthCalculateSignature方法代码示例

本文整理汇总了C#中FlickrNet.Flickr.OAuthCalculateSignature方法的典型用法代码示例。如果您正苦于以下问题:C# Flickr.OAuthCalculateSignature方法的具体用法?C# Flickr.OAuthCalculateSignature怎么用?C# Flickr.OAuthCalculateSignature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FlickrNet.Flickr的用法示例。


在下文中一共展示了Flickr.OAuthCalculateSignature方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDataResponseOAuth

        private static string GetDataResponseOAuth(Flickr flickr, string baseUrl, Dictionary<string, string> parameters)
        {
            string method = "POST";

            // Remove api key if it exists.
            if (parameters.ContainsKey("api_key")) parameters.Remove("api_key");
            if (parameters.ContainsKey("api_sig")) parameters.Remove("api_sig");

            // If OAuth Access Token is set then add token and generate signature.
            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.OAuthCalculateSignature(method, baseUrl, parameters, flickr.OAuthAccessTokenSecret);
                parameters.Add("oauth_signature", sig);
            }

            // Calculate post data, content header and auth header
            string data = OAuthCalculatePostData(parameters);
            string authHeader = OAuthCalculateAuthHeader(parameters);

            // Download data.
            try
            {
                return DownloadData(method, baseUrl, data, PostContentType, authHeader);
            }
            catch (WebException ex)
            {
                if (ex.Status != WebExceptionStatus.ProtocolError) throw;

                var response = ex.Response as HttpWebResponse;
                if (response == null) throw;

                string responseData = null;

                using (var stream = response.GetResponseStream())
                {
                    if( stream != null)
                        using (var responseReader = new StreamReader(stream))
                        {
                            responseData = responseReader.ReadToEnd();
                            responseReader.Close();
                        }
                }
                if (response.StatusCode == HttpStatusCode.BadRequest ||
                    response.StatusCode == HttpStatusCode.Unauthorized)
                {

                    throw new OAuthException(responseData, ex);
                }

                if (String.IsNullOrEmpty(responseData)) throw;
                throw new WebException("WebException occurred with the following body content: " + responseData, ex, ex.Status, ex.Response);
            }
        }
开发者ID:MichaelAzar,项目名称:flickr-net,代码行数:57,代码来源:FlickrResponderSync.cs

示例2: GetDataResponseOAuthAsync

        private static async Task<FlickrResult<string>> GetDataResponseOAuthAsync(Flickr flickr, string hashCall, string baseUrl, Dictionary<string, string> parameters)
        {
            string method = "POST";

            // Remove api key if it exists.
            if (parameters.ContainsKey("api_key")) parameters.Remove("api_key");
            if (parameters.ContainsKey("api_sig")) parameters.Remove("api_sig");

            // If OAuth Access Token is set then add token and generate signature.
            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.OAuthCalculateSignature(method, baseUrl, parameters, flickr.OAuthAccessTokenSecret);
                parameters.Add("oauth_signature", sig);
            }

            // Calculate post data, content header and auth header
            string data = OAuthCalculatePostData(parameters);
            string authHeader = OAuthCalculateAuthHeader(parameters);

            // Download data.
            try
            {
                return  await DownloadDataAsync(method, hashCall, baseUrl, data, PostContentType, authHeader);
            }
            catch (WebException ex)
            {
                //if (ex.Status != WebExceptionStatus.ProtocolError) throw;
                Debug.WriteLine("ERR - [" + baseUrl + "] " + ex.Message);
                HttpWebResponse response = ex.Response as HttpWebResponse;
                if (response == null) throw;

                if (response.StatusCode != HttpStatusCode.BadRequest && response.StatusCode != HttpStatusCode.Unauthorized) throw;

                using (StreamReader responseReader = new StreamReader(response.GetResponseStream()))
                {
                    string responseData = responseReader.ReadToEnd();
                    

                    throw new OAuthException(responseData, ex);
                }
            }

            //return null;
        }
开发者ID:liquidboy,项目名称:X,代码行数:48,代码来源:FlickrResponderAsync.cs

示例3: GetDataResponseOAuthAsync

 private static void GetDataResponseOAuthAsync(Flickr flickr, string baseUrl, Dictionary<string, string> parameters, Action<FlickrResult<string>> callback)
 {
     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 str = flickr.OAuthCalculateSignature("POST", baseUrl, parameters, flickr.OAuthAccessTokenSecret);
     parameters.Add("oauth_signature", str);
       }
       string data = FlickrResponder.OAuthCalculatePostData(parameters);
       string authHeader = FlickrResponder.OAuthCalculateAuthHeader(parameters);
       try
       {
     FlickrResponder.DownloadDataAsync("POST", baseUrl, data, "application/x-www-form-urlencoded", authHeader, callback);
       }
       catch (WebException ex)
       {
     HttpWebResponse httpWebResponse = ex.Response as HttpWebResponse;
     if (httpWebResponse == null)
       throw;
     else if (httpWebResponse.StatusCode != HttpStatusCode.BadRequest && httpWebResponse.StatusCode != HttpStatusCode.Unauthorized)
     {
       throw;
     }
     else
     {
       using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
       {
     string response = streamReader.ReadToEnd();
     streamReader.Close();
     throw new OAuthException(response, (Exception) ex);
       }
     }
       }
 }
开发者ID:rmck,项目名称:FlickrNet,代码行数:39,代码来源:FlickrResponder.cs

示例4: GetDataResponseOAuth

 private static string GetDataResponseOAuth(Flickr flickr, string baseUrl, Dictionary<string, string> parameters)
 {
     string method = "POST";
       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 str = flickr.OAuthCalculateSignature(method, baseUrl, parameters, flickr.OAuthAccessTokenSecret);
     parameters.Add("oauth_signature", str);
       }
       string data = FlickrResponder.OAuthCalculatePostData(parameters);
       string authHeader = FlickrResponder.OAuthCalculateAuthHeader(parameters);
       try
       {
     return FlickrResponder.DownloadData(method, baseUrl, data, "application/x-www-form-urlencoded", authHeader);
       }
       catch (WebException ex)
       {
     if (ex.Status != WebExceptionStatus.ProtocolError)
     {
       throw;
     }
     else
     {
       HttpWebResponse httpWebResponse = ex.Response as HttpWebResponse;
       if (httpWebResponse == null)
       {
     throw;
       }
       else
       {
     string response = (string) null;
     using (Stream responseStream = httpWebResponse.GetResponseStream())
     {
       if (responseStream != null)
       {
         using (StreamReader streamReader = new StreamReader(responseStream))
         {
           response = streamReader.ReadToEnd();
           streamReader.Close();
         }
       }
     }
     if (httpWebResponse.StatusCode == HttpStatusCode.BadRequest || httpWebResponse.StatusCode == HttpStatusCode.Unauthorized)
       throw new OAuthException(response, (Exception) ex);
     if (!string.IsNullOrEmpty(response))
       throw new WebException("WebException occurred with the following body content: " + response, (Exception) ex, ex.Status, ex.Response);
     throw;
       }
     }
       }
 }
开发者ID:rmck,项目名称:FlickrNet,代码行数:56,代码来源:FlickrResponder.cs

示例5: GetDataResponseOAuthAsync

        private static void GetDataResponseOAuthAsync(Flickr flickr, string baseUrl, Dictionary<string, string> parameters, Action<FlickrResult<string>> callback)
        {
            const string method = "POST";

            // Remove api key if it exists.
            if (parameters.ContainsKey("api_key")) parameters.Remove("api_key");
            if (parameters.ContainsKey("api_sig")) parameters.Remove("api_sig");

            // If OAuth Access Token is set then add token and generate signature.
            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.OAuthCalculateSignature(method, baseUrl, parameters, flickr.OAuthAccessTokenSecret);
                parameters.Add("oauth_signature", sig);
            }

            // Calculate post data, content header and auth header
            string data = OAuthCalculatePostData(parameters);
            string authHeader = OAuthCalculateAuthHeader(parameters);

            // Download data.
            try
            {
                DownloadDataAsync(method, baseUrl, data, PostContentType, authHeader, callback);
            }
            catch (WebException ex)
            {
                var response = ex.Response as HttpWebResponse;
                if (response == null) throw;

                if (response.StatusCode != HttpStatusCode.BadRequest && response.StatusCode != HttpStatusCode.Unauthorized) throw;

                using (var responseReader = new StreamReader(response.GetResponseStream()))
                {
                    string responseData = responseReader.ReadToEnd();
                    responseReader.Close();

                    throw new OAuthException(responseData, ex);
                }
            }
        }
开发者ID:ericleigh007,项目名称:flickr-net,代码行数:44,代码来源:FlickrResponderAsync.cs


注:本文中的FlickrNet.Flickr.OAuthCalculateSignature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。