本文整理汇总了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);
}
}
示例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;
}
示例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);
}
}
}
}
示例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;
}
}
}
}
示例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);
}
}
}