Imgur API (400 Error)

To whom it may concern,

Am I missing something? Trying to do a simple post to Imgur via their API.

My HTML

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

My JavaScript (w/o my imgur client id)

$scope.imgurTime = function(){
      console.log($scope.profilePicture);
        $.ajax({
            url: 'https://api.imgur.com/3/upload',
            headers: {
                'Authorization': 'Client-ID < a;lskdjfal;sdfj >'
            },
            type: 'POST',
            data: {
                'image': document.getElementById('profPic').value
            },
            success: function() { console.log('cool'); }
        })
}

Browser Error

POST https://api.imgur.com/3/upload 400 (Bad Request)

Thanks in advance for any enlightenment on this subject

Upvotes: 0

Views: 1818

Answers (1)

To anyone reading this post, realize, for a second, the utter silliness of my inquiry...

First mistake: Well, kinda a mistake -- I used ajax in an Angular app where I could have and should have just used Angular's built-in $http service.

Second: I requested the Imgur API to do something before authorizing myself. They tell you to do this RIGHT in the [documentation][1], 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); });

Upvotes: 1

Related Questions