使用 instagram api 的访问控制允许来源
我正在尝试使用以下代码获取我的 Instagram 供稿
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'
});
我得到的错误是
请求的资源上不存在Access-Control-Allow-Origin"标头.
有解决办法吗?
推荐答案
Instagram API 支持 JSONP,所以在 url 中添加 &callback=? 并添加 dataType: "jsonp" 到 $.ajax() 调用,如下所示:
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"
});
相关文章