本文介紹了使用 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"
});
這篇關于使用 instagram api 的訪問控制允許來源的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!