AngularJS POST (400 Bad Request)

1,411 views
Skip to first unread message

asimpl...@gmail.com

unread,
Aug 9, 2015, 4:24:14 PM8/9/15
to Imgur
Hi all! I'm new here, but maybe I can introduce myself with an issue I'm having with the imgur API! The code below returns a 400 Bad Request error, but I can't for the life of me figure out why : )

(please note, the client id was replaced with gibberish, but I have registered my app and have a real one.)

**HTML code**

<form>
<input id="profPic" type="file" name="pic" accept="image/*">
<button class="btn" ng-click="imgurTime()" type="submit">
Imgur Upload
</button>
</form>


**JavaScript code**

$scope.imgurTime = function(i){
console.log("The value: " + document.getElementById('profPic').value);
$http({
method: 'POST',
url: 'https://api.imgur.com/3/upload',
headers: {
'Authorization': 'Client-ID 1234lkj123lkj324'
},
data: document.getElementById('profPic').value
}).success(function(){
console.log("successfully posted!");
})
}

SEOAJ

unread,
Aug 10, 2015, 5:30:52 PM8/10/15
to Imgur
Same question as above.
I am using the following PHP code which worked well until today.
Somebody please advise.

$client_id = "xxxxxxxxxxxxxxx";
$image = file_get_contents($fname);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => base64_encode($image)));
$reply = curl_exec($ch);
curl_close($ch);
$reply = json_decode($reply);

---------------------

405 Not Allowed


asimpl...@gmail.com

unread,
Aug 26, 2015, 10:34:51 PM8/26/15
to Imgur
To anyone reading this post, realize, for a second, the utter silliness of my inquiry...

I requested the Imgur API to do something before authorizing myself. They tell you to do this RIGHT in the documentation, https://api.imgur.com/oauth2, so there's really no excuse to sidestep this.

Thus, all I needed to do to authorize is, first, do an

$http.get('https://api.imgur.com/oauth2/authorize?client_id=<client_id>&response_type=<response_type>').then(function(data){ console.log(awesomeImgurData); });

and it's good to go. Accessing the Imgur API with a MEAN application has never been more simple.

Reply all
Reply to author
Forward
0 new messages