Imgur API version 3 download examples?

I am trying to add this functionality to the C # Windows application that I have in development for uploading images to Imgur.

Unfortunately, this must be Imgur, as this site is a must.

The problem is that any C # code code that I can find is old and does not seem to work with their version 3 API.

So I was wondering if anyone with experience in this area could help me.

I would rather boot using the OAuth option rather than anonymous, but the latter can be used as an example if necessary.

EDIT:

One part that I don’t particularly get is how I can take the authorization step while remaining in the desktop application. An authorization step requires opening a web page on which the user is asked whether the application is allowed to use their data or not.

How to do this for a desktop application?

+4
source share
1 answer

Before you begin, you need to register your application in order to get the client ID and client secret. I suppose you already know that. Details can be found in the official Imgur API Documentation .

Regarding authentication, you are right, the user must visit a web page and capture and allow your appeal there. You can embed a Webbrowser control in an application or simply point the user to a web page.

Here are some unverified codes that should work with minor changes.

class Program { const string ClientId = "abcdef123"; const string ClientSecret = "Secret"; static void Main(string[] args) { string Pin = GetPin(ClientId, ClientSecret); string Tokens = GetToken(ClientId, ClientSecret, Pin); // Updoad Images or whatever :) } public static string GetPin(string clientId, string clientSecret) { string OAuthUrlTemplate = "https://api.imgur.com/oauth2/authorize?client_id={0}&response_type={1}&state={2}"; string RequestUrl = String.Format(OAuthUrlTemplate, clientId, "pin", "whatever"); string Pin = String.Empty; // Promt the user to browse to that URL or show the Webpage in your application // ... return Pin; } public static ImgurToken GetToken(string clientId, string clientSecret, string pin) { string Url = "https://api.imgur.com/oauth2/token/"; string DataTemplate = "client_id={0}&client_secret={1}&grant_type=pin&pin={2}"; string Data = String.Format(DataTemplate, clientId, clientSecret, pin); using(WebClient Client = new WebClient()) { string ApiResponse = Client.UploadString(Url, Data); // Use some random JSON Parser, youΒ΄ll get access_token and refresh_token var Deserializer = new JavaScriptSerializer(); var Response = Deserializer.DeserializeObject(ApiResponse) as Dictionary<string, object>; return new ImgurToken() { AccessToken = Convert.ToString(Response["access_token"]), RefreshToken = Convert.ToString(Response["refresh_token"]) }; } } } public class ImgurToken { public string AccessToken { get; set; } public string RefreshToken { get; set; } } 
+6
source

All Articles