Some oAuth fixes for Imgur & Photobucket. Still having problems with Photobucket...

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2026 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-09-12 12:43:02 +00:00
commit f447fb8b72
11 changed files with 165 additions and 118 deletions

View file

@ -32,9 +32,6 @@ namespace GreenshotPhotobucketPlugin {
/// </summary>
[IniSection("Photobucket", Description="Greenshot Photobucket Plugin configuration")]
public class PhotobucketConfiguration : IniSection {
[IniProperty("PhotobucketApiUrl", Description = "Url to Photobucket system.", DefaultValue = "http://api.photobucket.com")]
public string PhotobucketApiUrl;
[IniProperty("UploadFormat", Description="What file type to use for uploading", DefaultValue="png")]
public OutputFormat UploadFormat;
[IniProperty("UploadJpegQuality", Description="JPEG file save quality in %.", DefaultValue="80")]

View file

@ -117,22 +117,24 @@ namespace GreenshotPhotobucketPlugin {
host.SaveToStream(image, stream, outputSettings);
try {
string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails));
PhotobucketInfo PhotobucketInfo = null;
PhotobucketInfo photobucketInfo = null;
// Run upload in the background
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("photobucket", LangKey.communication_wait),
delegate() {
PhotobucketInfo = PhotobucketUtils.UploadToPhotobucket(stream.GetBuffer(), (int)stream.Length, captureDetails.Title, filename);
photobucketInfo = PhotobucketUtils.UploadToPhotobucket(stream.GetBuffer(), (int)stream.Length, captureDetails.Title, filename);
}
);
// This causes an exeption if the upload failed :)
LOG.DebugFormat("Uploaded to Photobucket page: " + photobucketInfo.Page);
uploadURL = null;
try {
if (config.UsePageLink) {
uploadURL = PhotobucketInfo.Page;
Clipboard.SetText(PhotobucketInfo.Page);
uploadURL = photobucketInfo.Page;
Clipboard.SetText(photobucketInfo.Page);
} else {
uploadURL = PhotobucketInfo.Original;
Clipboard.SetText(PhotobucketInfo.Original);
uploadURL = photobucketInfo.Original;
Clipboard.SetText(photobucketInfo.Original);
}
} catch (Exception ex) {
LOG.Error("Can't write to clipboard: ", ex);

View file

@ -93,20 +93,30 @@ namespace GreenshotPhotobucketPlugin {
uploadRequest.Append("&filename=");
uploadRequest.Append(EscapeText(filename));
}
string url = config.PhotobucketApiUrl + "/album/greenshot/upload";
string url = "http://api.photobucket.com/album/greenshot/upload";
string responseString;
OAuthHelper oAuth = new OAuthHelper();
// This url is configured in the Photobucket API settings in the Photobucket site!!
oAuth.CallbackUrl = "http://getgreenshot.org";
oAuth.AccessTokenUrl = "http://api.photobucket.com/login/access";
oAuth.AuthorizeUrl = " http://photobucket.com/apilogin/login";
oAuth.AuthorizeUrl = "http://photobucket.com/apilogin/login";
oAuth.RequestTokenUrl = "http://api.photobucket.com/login/request";
oAuth.ConsumerKey = "fill-in";
oAuth.ConsumerSecret = "fill-in";
oAuth.UserAgent = "Greenshot";
oAuth.BrowserWidth = 1010;
oAuth.BrowserHeight = 400;
oAuth.CheckVerifier = false;
if (string.IsNullOrEmpty(config.PhotobucketToken)) {
LOG.Debug("Creating Photobucket Token");
oAuth.getRequestToken();
try {
oAuth.getRequestToken();
} catch (Exception ex) {
LOG.Error(ex);
throw new NotSupportedException("Photobucket is not available: " + ex.Message);
}
LOG.Debug("Authorizing Photobucket");
if (string.IsNullOrEmpty(oAuth.authorizeToken("Photobucket authorization"))) {
return null;
}