2016-03-19 33 views
0

我試圖做一個簡單的請求的Instagram如下:意外標記:jQuery的Ajax調用

$.getJSON("https://www.instagram.com/kidsfromthe90sband/media/?callback=?", 
 
    function(data) { 
 
    alert(JSON.stringify(data)); 
 
    });

http://jsfiddle.net/FPhcr/731/

但是它說,未捕獲的SyntaxError:意外的標記:在控制檯中,但uri是可以的,如果我在Postman中或直接在瀏覽器中運行它,它就可以工作。我搜索了其他問題,但我無法知道我的錯誤。 謝謝。

編輯

如果我不把一個回調=?還有另一個錯誤:沒有「訪問控制允許來源」標頭出現在所請求的資源

+1

這是不是一個正確的方式來要求instagram的api,你應該看看instagram的開發人員文檔 – mygoare

+0

https://www.instagram.com/developer/ – epascarello

回答

2

Actually when you are using any social app data like for facebook,linkedin or instagram in your case etc you need to register your app there so you get unique token & id which help them to authenticate you.So,they can fullfill your request through their provided public API .

它的發生,因爲按照JSONP結果/性反應應該內回調被包裹未在這種情況下發生。

編輯:

你需要訂閱的Instagram之後,你得到你的ACCESS-TOKEN。

然後形成URL像這樣的

https://api.instagram.com/v1/tags/coffee/media/recent?access_token=ACCESS-TOKEN&callback=callbackFunction 

,這將給JSONP。

請參考這裏更多

  1. devloper
  2. endpoints
+0

所以,我應該如何使電話使它的工作?如果我不把回調=?'還有另一個錯誤:沒有'訪問控制允許來源'標題出現在請求的資源 –

+0

其服務器端實施 –

+0

我認爲你需要ACCESS_TOKEN Instagram API然後嘗試與這一個 –

0

你對待好像它會返回JSONP數據的API,但事實並非如此。所以jQuery然後嘗試評估純JSON返回爲JSONP並記錄錯誤。

您必須爲JSONP找到正確的API端點,有一個文檔可以在這裏找到:https://www.instagram.com/developer/endpoints/