401 unauthorized error when querying imgur api

1.4k Views Asked by At

I am trying to retrieve pictures from imgur to display on my blog by using an ajax request in jQuery

  $.ajax({
      type: "GET",
      url: "https://api.imgur.com/3/image/kvM6pxn.json",
      dataType: "jsonp",
      beforeSend: function(xhr) {
        xhr.setRequestHeader('Authorization', 'Client-ID <client-id>');
      },
      success: function(data) {
        console.log(data);
      }
    });

but I am getting a 401 unauthorized error. Can anyone tell me what I am doing wrong? Thanks

1

There are 1 best solutions below

0
On

Changing dataType from jsonp to json fixed it. Not really sure why though...