json - unexpected token : from angular $http.jsonp request to Instagram API -
i'm making request authorized instagram account display images on site. originally, running no 'access-control-allow-origin' when using angular's $http.get(...
.
from matt's answer in question, seems can use getjson
, or angular $http.jsonp
, bypass issue. that guy's answer says "jsonp trick overcome xmlhttprequest same domain policy".
so, i'm no longer getting problem, , getting json payload:
{"pagination":{"next_url":"https:\/\/api.instagram.com... etc
but getting ambiguous error:
uncaught syntaxerror: unexpected token :
this response instagram api, i'm not sure why there'd syntax error on inbound json. also, it's hard locate error since jsonp
response on single line... error reported.
the preview shows i'm getting full payload:
i found issue. unfortunately there no javascript libraries this, in instagram api docs, jsonp can wrap response callback json payload wrapped in <script>
tags (more info on jsonp here), therefore not blocked access control allow origin.
response:
callbackfunction({ ... });
so, in http request uri, add in callback parameter. since using angular, docs $http.jsonp()
requests specify callback string "json_callback".
so, request url angular be:
$http.jsonp( 'https://api.instagram.com/v1/tags/coffee/media/recent? access_token=access-token&callback=json_callback') .success(function(data) {...
Comments
Post a Comment