• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

C# Imgur API [C#]

Status
Not open for further replies.

fudmario

Leech
User
Joined
Feb 23, 2013
Messages
202
Reputation
0
Reaction score
1,098
Points
143
Credits
0
‎12 Years of Service‎
68%
[HIDE-THANKS][LENGUAJE=C#]

using System.Net;

using System.Text;

using System.IO;

string ClientId = "Put your client id here";

public object UploadImage(string image)

{

WebClient w = new WebClient();

w.Headers.Add("Authorization", "Client-ID " + ClientId);

System.Collections.Specialized.NameValueCollection Keys = new System.Collections.Specialized.NameValueCollection();

try {

Keys.Add("image", Convert.ToBase64String(File.ReadAllBytes(image)));

byte[] responseArray = w.UploadValues("https://api.imgur.com/3/image", Keys);

dynamic result = Encoding.ASCII.GetString(responseArray);

System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("link\":\"(.*?)\"");

Match match = reg.Match(result);

string url = match.ToString.Replace("link\":\"", "").Replace("\"", "").Replace("\\/", "/");

return url;

} catch (Exception s) {

MessageBox.Show("Something went wrong. " + s.Message);

return "Failed!";

}

}

[/LENGUAJE]

[LENGUAJE=C#]//Ejemplo de Uso:

//string url = UploadImage(textbox1.text);

//path to the image

//messagebox.show(url);

[/LENGUAJE]

Fuente: pc-tips.net[/HIDE-THANKS]

 
Status
Not open for further replies.
Back
Top