簡體   English   中英

Imgur API(400錯誤)

[英]Imgur API (400 Error)

敬啟者,

我想念什么嗎? 嘗試通過其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'); }
        })
}

瀏覽器錯誤

POST https://api.imgur.com/3/upload 400(錯誤請求)

在此先感謝您對本主題的任何啟發

對於閱讀此帖子的任何人,請一秒鍾意識到我的詢問完全愚蠢……

第一個錯誤:恩,這是一個錯誤-我在Angular應用程序中使用了Ajax,在該應用程序中,我本應該也應該使用Angular的內置$ http服務。

第二:我要求Imgur API在授權自己之前做點事情。 他們告訴您在[documentation] [1]中正確執行此操作,因此實際上沒有任何理由回避此操作。 因此,我需要做的就是授權,首先要做一個$http.get('https://api.imgur.com/oauth2/authorize?client_id=<client_id>&response_type=<response_type>').then(function(data){ console.log(awesomeImgurData); });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM