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;
}