private static void GetDataResponseOAuthAsync(Flickr flickr, string baseUrl, Dictionary <string, string> parameters, Action <FlickrResult <string> > callback) { const string method = ""; // 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(); throw new OAuthException(responseData, ex); } } }
public static void GetDataResponseAsync(Flickr flickr, string baseUrl, Dictionary <string, string> parameters, string url, Action <FlickrResult <string> > callback) { bool oAuth = parameters.ContainsKey("oauth_consumer_key"); if (oAuth) { GetDataResponseOAuthAsync(flickr, baseUrl, parameters, url, callback); } else { GetDataResponseNormalAsync(flickr, baseUrl, parameters, callback); } }