From c1e52f5b1625118f07280f6c7fc729b6d3586c30 Mon Sep 17 00:00:00 2001 From: RKrom Date: Fri, 14 Sep 2012 16:52:00 +0000 Subject: [PATCH] Refactored some Photobucket code, still getting 401 errors though. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2039 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- .../PhotobucketUtils.cs | 38 +++---------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/GreenshotPhotobucketPlugin/PhotobucketUtils.cs b/GreenshotPhotobucketPlugin/PhotobucketUtils.cs index 26e4c08d8..106d9293d 100644 --- a/GreenshotPhotobucketPlugin/PhotobucketUtils.cs +++ b/GreenshotPhotobucketPlugin/PhotobucketUtils.cs @@ -41,34 +41,6 @@ namespace GreenshotPhotobucketPlugin { private PhotobucketUtils() { } - /// - /// A wrapper around the EscapeDataString, as the limit is 32766 characters - /// See: http://msdn.microsoft.com/en-us/library/system.uri.escapedatastring%28v=vs.110%29.aspx - /// - /// - /// escaped data string - private static StringBuilder EscapeDataStringToStringBuilder(string dataString) { - StringBuilder result = new StringBuilder(); - int currentLocation = 0; - while (currentLocation < dataString.Length) { - string process = dataString.Substring(currentLocation,Math.Min(16384, dataString.Length-currentLocation)); - result.Append(Uri.EscapeDataString(process)); - currentLocation = currentLocation + 16384; - } - return result; - } - - private static string EscapeText(string text) { - string[] UriRfc3986CharsToEscape = new[] { "!", "*", "'", "(", ")" }; - LOG.DebugFormat("Text size {0}", text.Length); - StringBuilder escaped = EscapeDataStringToStringBuilder(text); - - for (int i = 0; i < UriRfc3986CharsToEscape.Length; i++) { - escaped.Replace(UriRfc3986CharsToEscape[i], Uri.HexEscape(UriRfc3986CharsToEscape[i][0])); - } - return escaped.ToString(); - } - /// /// Do the actual upload to Photobucket /// For more details on the available parameters, see: http://api.Photobucket.com/resources_anon @@ -82,16 +54,16 @@ namespace GreenshotPhotobucketPlugin { uploadRequest.Append("&type=base64"); // Add image uploadRequest.Append("&uploadfile="); - uploadRequest.Append(EscapeText(System.Convert.ToBase64String(imageData, 0, dataLength))); + uploadRequest.Append(OAuthHelper.UrlEncode3986(System.Convert.ToBase64String(imageData, 0, dataLength))); // add title if (title != null) { uploadRequest.Append("&title="); - uploadRequest.Append(EscapeText(title)); + uploadRequest.Append(OAuthHelper.UrlEncode3986(title)); } // add filename if (filename != null) { uploadRequest.Append("&filename="); - uploadRequest.Append(EscapeText(filename)); + uploadRequest.Append(OAuthHelper.UrlEncode3986(filename)); } string url = "http://api.photobucket.com/album/greenshot/upload"; string responseString; @@ -102,8 +74,8 @@ namespace GreenshotPhotobucketPlugin { oAuth.AccessTokenUrl = "http://api.photobucket.com/login/access"; oAuth.AuthorizeUrl = "http://photobucket.com/apilogin/login"; oAuth.RequestTokenUrl = "http://api.photobucket.com/login/request"; - oAuth.ConsumerKey = "fill-in"; - oAuth.ConsumerSecret = "fill-in"; + oAuth.ConsumerKey = ; + oAuth.ConsumerSecret = ; oAuth.UserAgent = "Greenshot"; oAuth.BrowserWidth = 1010; oAuth.BrowserHeight = 400;