Some time ago, I created a python function that took the image URL and passed it to Imgur API v2. Since I was informed that API v2 would be deprecated, I tried to do this using API v3.
As the Imgur API documentation says:
[Sending] the authorization header with your client_id along with your requests [...] also works if you want to anonymously upload images (without linking the image to your account). This allows us to find out which application is accessing the API. **
Authorization: YOURCLIENTID customer identifier
I donโt understand (especially with italics) if they mean that the title should be {'Authorization': 'Client-ID ' + clientID} , or {'Authorization: Client-ID ': clientID} , or {'Authorization:', 'Client-ID ' + clientID} , or some other option ...
Anyway, I tried, and this is what I got (using Python 2.7.3):
def sideLoad(imgURL): img = urllib.quote_plus(imgURL) req = urllib2.Request('https://api.imgur.com/3/image', urllib.urlencode([('image', img), ('key', clientSecret)])) req.add_header('Authorization', 'Client-ID ' + clientID) response = urllib2.urlopen(req) return response.geturl()
It seems to me that he does everything Imgur wants me to do: I have the correct endpoint passing data to urllib2.Request makes a POST request according to the Python docs, I pass the image parameter using the URL encoded in form, I also tried to give him the secret of my client as a POST parameter, as I had an error: I need an identifier (even if there is no mention of the need to use my client secret somewhere in the relevant documentation). I am adding an authorization header and it seems to be the correct form, so ... why am I getting the 400: Bad error message?
Side question: I could debug it myself if I could see the actual Imgur error, but since it returns an HTTP error status, Python dies and gives me one of these disgusting stack traces. Is there a way Python could whine and give me a JSON error message that I know Imgur is returning?