Tom Dippé
Tom Dippé

Reputation: 47

Authentication With Imgur API

So I'm writing a simple-ish script that can automatically download images from Imgur. I've come across the Imgur API but am struggling to get it to work. I registered an app but am not sure how to use it to be able to get information about images or albums. I do not want to be able to log in as a user or anything like that - just provide a URL of an album or a single image and be able to download it.

I've read that if I want to do this then I don't need to use the oauth stuff, I should just be able to use a client ID.

https://www.reddit.com/r/learnprogramming/comments/2uzxfv/how_do_i_get_fully_authenticated_to_use_imgurs_api/

The script I am writing is using Python, but just to test out the API I am typing the URL into the browser. If I go to the following URL:

https://api.imgur.com/3/album/qTt8G?client_id=MY_CLIENT_ID

Then I receive the following response:

{"data":{"error":"Authentication required","request":"/3/album/qTt8G","method":"GET"},"success":false,"status":401}

The full album URL is https://i.sstatic.net/EKvbU.jpg I've tried reading through the API docs, but am stuck with this.

Useful info:

https://api.imgur.com/oauth2

https://api.imgur.com/endpoints/album

Upvotes: 2

Views: 5817

Answers (2)

Mayank Nader
Mayank Nader

Reputation: 31

You have to provide the client-id in the header of the GET request. You are sending it using query parameters. HTTP Headers vs query parameters

You can use Postman for this. In Python code, you can use requests library:

import requests

url = "https://api.imgur.com/3/album/{{albumHash}}"

headers = {'Authorization': 'Client-ID {{clientId}}'}

response = requests.request("GET", url, headers=headers)

print(response.text)

Check out imgur api docs for more.

Upvotes: 3

Tom Dippé
Tom Dippé

Reputation: 47

In the end I just used the Imgur API helper that is available on Github to do all the work. Just needed to provide the client ID and secret.

https://github.com/Imgur/imgurpython

Upvotes: 0

Related Questions