Retrieving anonymous image information via Imgur API in C #

I am trying to anonymously get image data (e.g. image sizes) through the Imgur version 3 API version through C #. Their documentation states

The API requires that each client use OAuth 2 authentication. This means you will need to register your application and create access_code if you want to log in as a user.

For publicly accessible, public and anonymous resources, such as obtaining info images, viewing user comments, etc., all you have to do is send an authorization header with your client_id in your requests. This also works if you want to anonymously upload images (without an account-linked image), or if you want to create an anonymous album. This allows us to find out which application is accessing the API.

Authorization: Customer ID YOUR_CLIENT_ID

So, I added the client ID as a header to my HttpWebRequest. Here is my code below.

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://api.imgur.com/3/image/id/8ABRUYt"); webRequest.Headers.Add("Authorization", "Client-ID XXXXX"); Stream response = webRequest.GetResponse().GetResponseStream(); StreamReader reader = new StreamReader(response); string responseFromServer = reader.ReadToEnd(); Console.WriteLine(responseFromServer); reader.Close(); response.Close(); 

I get 404 error, but this image clearly exists β†’ http://imgur.com/8ABRUYt (Image of the Milky Way button). Am I doing something wrong?

+7
source share
1 answer

Your first line should read

 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://api.imgur.com/3/image/8ABRUYt"); 

The correct URL " https://api.imgur.com/3/image/ {id}" - {id} is your image id.

Your message helped me get started with just viewing the image with imgur! I would vote for you, but it takes 15 reputation :( I will answer you when I can :)

+3
source

All Articles