Imgur API(400 错误) [英] Imgur API (400 Error)

查看:32
本文介绍了Imgur API(400 错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能涉及的人,

我错过了什么吗?尝试通过他们的 API 向 Imgur 发布一个简单的帖子.

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

我的 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)

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'); }
        })
}

浏览器错误

POST https://api.imgur.com/3/upload 400(错误请求)

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

提前感谢您对此主题的任何启发

推荐答案

对于阅读这篇文章的任何人,请意识到我的询问是多么愚蠢......

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

第一个错误:嗯,有点错误——我在一个 Angular 应用程序中使用了 ajax,我可以并且应该使用 Angular 的内置 $http 服务.

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.

第二:在授权自己之前,我请求 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); });

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); });

这篇关于Imgur API(400 错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆