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:

enter image description here

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.

https://api.instagram.com/v1/tags/coffee/media/recent?access_token=access-token&callback=callbackfunction

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

Popular posts from this blog

command line - Use qwinsta in PowerShell ISE -

java - Incorrect order of records in M-M relationship in hibernate -

Python website log in: BIG-IP can not find session information in the request -