Reputation: 47
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.
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/endpoints/album
Upvotes: 2
Views: 5817
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
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