意外令牌:在 jQuery ajax 调用中

Unexpected token : in jQuery ajax call

我正在尝试向 instagram 发出一个简单的请求,如下所示:

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

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

但是它在控制台中显示 Uncaught SyntaxError: Unexpected token : 但 uri 没问题,如果我在 Postman 中或直接在浏览器中 运行 它就可以工作。我搜索了其他问题,但我无法知道我的错误。 谢谢。

编辑

如果我不回拨=?还有一个错误:请求的资源

上不存在 'Access-Control-Allow-Origin' header

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,结果 /responce 应该包装在回调中,而在这种情况下不会发生。

编辑:

您需要订阅 instagram,然后您才能获得 ACCESS-TOKEN。

然后像这样形成url

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

这将给出 jsonp。

更多请参考这里

  1. devloper
  2. endpoints

您将 API 视为 return JSONP 数据,但事实并非如此。因此 jQuery 然后尝试将纯 JSON return 计算为 JSONP 并记录错误。

您必须为 JSONP 找到正确的 API 端点,可以在此处找到文档:https://www.instagram.com/developer/endpoints/.