mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
Added non anonymous access for Imgur, is still in an initial state.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2015 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
79cbe548b0
commit
dcb66c5007
4 changed files with 89 additions and 27 deletions
15
GreenshotImgurPlugin/Forms/SettingsForm.Designer.cs
generated
15
GreenshotImgurPlugin/Forms/SettingsForm.Designer.cs
generated
|
@ -53,6 +53,7 @@ namespace GreenshotImgurPlugin {
|
|||
this.combobox_uploadimageformat = new GreenshotPlugin.Controls.GreenshotComboBox();
|
||||
this.label_upload_format = new GreenshotPlugin.Controls.GreenshotLabel();
|
||||
this.historyButton = new GreenshotPlugin.Controls.GreenshotButton();
|
||||
this.checkbox_anonymous_access = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
||||
this.checkbox_usepagelink = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
|
@ -126,6 +127,18 @@ namespace GreenshotImgurPlugin {
|
|||
this.historyButton.UseVisualStyleBackColor = true;
|
||||
this.historyButton.Click += new System.EventHandler(this.ButtonHistoryClick);
|
||||
//
|
||||
// checkbox_anonymous_access
|
||||
//
|
||||
this.checkbox_anonymous_access.AutoSize = true;
|
||||
this.checkbox_anonymous_access.LanguageKey = "imgur.anonymous_access";
|
||||
this.checkbox_anonymous_access.Location = new System.Drawing.Point(15, 80);
|
||||
this.checkbox_anonymous_access.Name = "checkbox_anonymous_access";
|
||||
this.checkbox_anonymous_access.PropertyName = "AnonymousAccess";
|
||||
this.checkbox_anonymous_access.SectionName = "Imgur";
|
||||
this.checkbox_anonymous_access.Size = new System.Drawing.Size(297, 17);
|
||||
this.checkbox_anonymous_access.TabIndex = 13;
|
||||
this.checkbox_anonymous_access.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkbox_usepagelink
|
||||
//
|
||||
this.checkbox_usepagelink.AutoSize = true;
|
||||
|
@ -143,6 +156,7 @@ namespace GreenshotImgurPlugin {
|
|||
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
||||
this.ClientSize = new System.Drawing.Size(387, 168);
|
||||
this.Controls.Add(this.checkbox_anonymous_access);
|
||||
this.Controls.Add(this.checkbox_usepagelink);
|
||||
this.Controls.Add(this.historyButton);
|
||||
this.Controls.Add(this.label_upload_format);
|
||||
|
@ -167,6 +181,7 @@ namespace GreenshotImgurPlugin {
|
|||
private GreenshotPlugin.Controls.GreenshotLabel label_url;
|
||||
private GreenshotPlugin.Controls.GreenshotButton buttonCancel;
|
||||
private GreenshotPlugin.Controls.GreenshotButton buttonOK;
|
||||
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_anonymous_access;
|
||||
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_usepagelink;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,12 @@ namespace GreenshotImgurPlugin {
|
|||
public bool UploadReduceColors;
|
||||
[IniProperty("UsePageLink", Description = "Use pagelink instead of direct link on the clipboard", DefaultValue = "False")]
|
||||
public bool UsePageLink;
|
||||
[IniProperty("AnonymousAccess", Description = "Use anonymous access to Imgur", DefaultValue="true")]
|
||||
public bool AnonymousAccess;
|
||||
[IniProperty("ImgurToken", Description = "The Imgur token", Encrypted=true, ExcludeIfNull=true)]
|
||||
public string ImgurToken;
|
||||
[IniProperty("ImgurTokenSecret", Description = "The Imgur token secret", Encrypted=true, ExcludeIfNull=true)]
|
||||
public string ImgurTokenSecret;
|
||||
|
||||
[IniProperty("ImgurUploadHistory", Description="Imgur upload history (ImgurUploadHistory.hash=deleteHash)")]
|
||||
public Dictionary<string, string> ImgurUploadHistory;
|
||||
|
|
|
@ -132,38 +132,67 @@ namespace GreenshotImgurPlugin {
|
|||
// Add image
|
||||
uploadRequest.Append("image=");
|
||||
uploadRequest.Append(EscapeText(System.Convert.ToBase64String(imageData, 0, dataLength)));
|
||||
// add type
|
||||
uploadRequest.Append("&type=base64");
|
||||
// add key
|
||||
uploadRequest.Append("&");
|
||||
uploadRequest.Append("key=");
|
||||
uploadRequest.Append("&key=");
|
||||
uploadRequest.Append(IMGUR_ANONYMOUS_API_KEY);
|
||||
// add title
|
||||
if (title != null) {
|
||||
uploadRequest.Append("&");
|
||||
uploadRequest.Append("title=");
|
||||
uploadRequest.Append("&title=");
|
||||
uploadRequest.Append(EscapeText(title));
|
||||
}
|
||||
// add filename
|
||||
if (filename != null) {
|
||||
uploadRequest.Append("&");
|
||||
uploadRequest.Append("name=");
|
||||
uploadRequest.Append("&name=");
|
||||
uploadRequest.Append(EscapeText(filename));
|
||||
}
|
||||
string url = config.ImgurApiUrl + "/upload";
|
||||
HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(url);
|
||||
|
||||
webRequest.Method = "POST";
|
||||
webRequest.ContentType = "application/x-www-form-urlencoded";
|
||||
webRequest.ServicePoint.Expect100Continue = false;
|
||||
|
||||
using(StreamWriter streamWriter = new StreamWriter(webRequest.GetRequestStream())) {
|
||||
streamWriter.Write(uploadRequest.ToString());
|
||||
}
|
||||
string url;
|
||||
string responseString;
|
||||
using (WebResponse response = webRequest.GetResponse()) {
|
||||
LogCredits(response);
|
||||
Stream responseStream = response.GetResponseStream();
|
||||
StreamReader responseReader = new StreamReader(responseStream);
|
||||
responseString = responseReader.ReadToEnd();
|
||||
|
||||
if (config.AnonymousAccess) {
|
||||
url = config.ImgurApiUrl + "/upload";
|
||||
HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(url);
|
||||
|
||||
webRequest.Method = "POST";
|
||||
webRequest.ContentType = "application/x-www-form-urlencoded";
|
||||
webRequest.ServicePoint.Expect100Continue = false;
|
||||
|
||||
using(StreamWriter streamWriter = new StreamWriter(webRequest.GetRequestStream())) {
|
||||
streamWriter.Write(uploadRequest.ToString());
|
||||
}
|
||||
using (WebResponse response = webRequest.GetResponse()) {
|
||||
LogCredits(response);
|
||||
Stream responseStream = response.GetResponseStream();
|
||||
StreamReader responseReader = new StreamReader(responseStream);
|
||||
responseString = responseReader.ReadToEnd();
|
||||
}
|
||||
|
||||
} else {
|
||||
url = config.ImgurApiUrl + "/account/images";
|
||||
OAuthHelper oAuth = new OAuthHelper();
|
||||
oAuth.CallbackUrl = "http://getgreenshot.org";
|
||||
oAuth.AccessTokenUrl = "https://api.imgur.com/oauth/access_token";
|
||||
oAuth.AuthorizeUrl = "https://api.imgur.com/oauth/authorize";
|
||||
oAuth.RequestTokenUrl = "https://api.imgur.com/oauth/request_token";
|
||||
oAuth.ConsumerKey = "907d4455b8c38144d68c4f72190af4c40504a0ac7";
|
||||
oAuth.ConsumerSecret = "d33902ef409fea163ab755454c15b3d0";
|
||||
oAuth.UserAgent = "Greenshot";
|
||||
if (string.IsNullOrEmpty(config.ImgurToken)) {
|
||||
LOG.Debug("Creating Imgur Token");
|
||||
oAuth.getRequestToken();
|
||||
if (string.IsNullOrEmpty(oAuth.authorizeToken("Imgur authorization"))) {
|
||||
return null;
|
||||
}
|
||||
string accessToken = oAuth.getAccessToken();
|
||||
config.ImgurToken = oAuth.Token;
|
||||
config.ImgurTokenSecret = oAuth.TokenSecret;
|
||||
} else {
|
||||
LOG.Debug("Using stored Imgur Token");
|
||||
oAuth.Token = config.ImgurToken;
|
||||
oAuth.TokenSecret = config.ImgurTokenSecret;
|
||||
}
|
||||
responseString = oAuth.oAuthWebRequest(OAuthHelper.Method.POST, url, uploadRequest.ToString());
|
||||
}
|
||||
LOG.Info(responseString);
|
||||
ImgurInfo imgurInfo = ImgurInfo.ParseResponse(responseString);
|
||||
|
@ -262,7 +291,7 @@ namespace GreenshotImgurPlugin {
|
|||
} catch {}
|
||||
}
|
||||
|
||||
private static void ImgurOAuthExample() {
|
||||
public static void ImgurOAuthExample() {
|
||||
OAuthHelper oAuth = new OAuthHelper();
|
||||
oAuth.CallbackUrl = "http://getgreenshot.org";
|
||||
oAuth.AccessTokenUrl = "https://api.imgur.com/oauth/access_token";
|
||||
|
@ -271,12 +300,21 @@ namespace GreenshotImgurPlugin {
|
|||
oAuth.ConsumerKey = "907d4455b8c38144d68c4f72190af4c40504a0ac7";
|
||||
oAuth.ConsumerSecret = "d33902ef409fea163ab755454c15b3d0";
|
||||
oAuth.UserAgent = "Greenshot";
|
||||
oAuth.getRequestToken();
|
||||
if (string.IsNullOrEmpty(oAuth.authorizeToken("Imgur authorization"))) {
|
||||
return;
|
||||
if (string.IsNullOrEmpty(config.ImgurToken)) {
|
||||
LOG.Debug("Creating Imgur Token");
|
||||
oAuth.getRequestToken();
|
||||
if (string.IsNullOrEmpty(oAuth.authorizeToken("Imgur authorization"))) {
|
||||
return;
|
||||
}
|
||||
string accessToken = oAuth.getAccessToken();
|
||||
config.ImgurToken = oAuth.Token;
|
||||
config.ImgurTokenSecret = oAuth.TokenSecret;
|
||||
} else {
|
||||
LOG.Debug("Using stored Imgur Token");
|
||||
oAuth.Token = config.ImgurToken;
|
||||
oAuth.TokenSecret = config.ImgurTokenSecret;
|
||||
}
|
||||
string accessToken = oAuth.getAccessToken();
|
||||
MessageBox.Show(oAuth.oAuthWebRequest(OAuth.Method.GET, "http://api.imgur.com/2/account", null));
|
||||
System.Windows.Forms.MessageBox.Show(oAuth.oAuthWebRequest(OAuthHelper.Method.GET, "http://api.imgur.com/2/account", null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,9 @@
|
|||
<resource name="delete_title">
|
||||
Delete Imgur {0}
|
||||
</resource>
|
||||
<resource name="anonymous_access">
|
||||
Use anonymous access
|
||||
</resource>
|
||||
<resource name="use_page_link">
|
||||
Use page link instead of image link on clipboard
|
||||
</resource>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue