Beispiel #1
0
        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;
        }
        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);
            }
        }
        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);
                }
            }
        }
Beispiel #4
0
        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;
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
 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);
       }
     }
       }
 }
Beispiel #7
0
 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;
       }
     }
       }
 }
        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);
                }
            }
        }