Access-Control-Allow-Origin with instagram api

2019-01-28 11:31发布

I am trying to get my instagram feed with the following code

$.ajax({
      url: 'https://api.instagram.com/v1/users/xxxxxxx/media/recent/?access_token=xxxxxxxxxxx',

      error: function() {
        alert('error');
      },

      success: function(data) {
       alert('yes');
      },
      type: 'GET'
   });

The error I am getting is

No 'Access-Control-Allow-Origin' header is present on the requested resource.

Is there a work around?

1条回答
ゆ 、 Hurt°
2楼-- · 2019-01-28 11:39

Instagram API supports JSONP, so add &callback=? to the url and add dataType: "jsonp" to the $.ajax() call, like below:

$.ajax({
      url: 'https://api.instagram.com/v1/users/xxxxxxx/media/recent/?access_token=xxxxxxxxxxx&callback=?',

      error: function() {
        alert('error');
      },

      success: function(data) {
       alert('yes');
      },
      type: 'GET',
      dataType: "jsonp"
   });
查看更多
登录 后发表回答