可能涉及到的人,
我错过了什么吗?尝试通过 Imgur 的 API 向 Imgur 发布一个简单的帖子。
我的 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>
我的 JavaScript(没有我的 imgur 客户端 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'); }
})
}
浏览器错误
发布https://api.imgur.com/3/upload 400(错误请求)
提前感谢您对此主题的任何启发
最佳答案
对于阅读这篇文章的任何人,请立即意识到我的询问是多么愚蠢......
第一个错误:嗯,有点错误——我在 Angular 应用程序中使用了 ajax,我可以而且应该使用 Angular 的内置 $http 服务。
第二:我在授权自己之前请求 Imgur API 执行某些操作。他们在[文档][1]中告诉您要正确执行此操作,因此确实没有借口回避这一点。因此,我需要做的授权就是首先执行 $http.get('https://api.imgur.com/oauth2/authorize?client_id=<client_id>&response_type=<response_type>').then(function(data){ console.log(awesomeImgurData); });
关于javascript - Imgur API(400 错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31907282/