All the examples I find online are of earlier versions of the Imgur API or non JS code all of which uses an API key which doesn't exist in the newer API. Instead you get a client_id
and secret
. Anyone have example code that shows how an image can be uploaded to Imgur through JavaScript (or jQuery) using version 3 of their API?
Imgur API Version 3 JavaScript upload example
Asked Answered
$.ajax({
url: 'https://api.imgur.com/3/image',
headers: {
'Authorization': 'Client-ID YOUR_CLIENT_ID'
},
type: 'POST',
data: {
'image': 'helloworld.jpg'
},
success: function() { console.log('cool'); }
});
I get this message: " POST api.imgur.com/3/image 403 (Permission Denied) " –
Dactylogram
@Aleedis awesome thanks so much. Been confused about this for weeks. –
Elvaelvah
@acudars did you change this part: "YOUR_CLIENT_ID" with the client id you recieved after registering your app here api.imgur.com/oauth2/addclient ? –
Elvaelvah
why the response I get is 1203 image over capacity? even after I used a very small image? –
Pacify
@Aleedis Why i have error?
$.ajax({ url: 'https://api.imgur.com/3/image', headers: { 'Authorization': '6b72b886602****' }, type: 'POST', data: { 'image': '111.PNG' }, success: function() { console.log('cool'); } });
–
Selfsatisfied I sill get permission denied after putting my own client id as well. –
Valparaiso
Im getting error 429, SO link: #66874183 –
Tristan
Building on @vin's example here is one:
$(document).ready(function() {
$.ajax({
url: 'https://api.imgur.com/3/image',
headers: {
'Authorization': 'Client-ID a1b2c3d4e5'
},
type: 'POST',
data: {
'image': image
},
success: function(data, status) {
console.log("Data: " + data.data.link + "\nStatus: " status);
console.log(data.data.link)
}
});
});
This lets you save the url to the file.
© 2022 - 2024 — McMap. All rights reserved.