mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
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
This commit is contained in:
parent
a20619b265
commit
c1e52f5b16
1 changed files with 5 additions and 33 deletions
|
@ -41,34 +41,6 @@ namespace GreenshotPhotobucketPlugin {
|
|||
private PhotobucketUtils() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
/// <param name="dataString"></param>
|
||||
/// <returns>escaped data string</returns>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue