You have to add another &callback=?
for next_url
Modify like this and try it works:
if(next_url!=undefined)
{
url=next_url + "&callback=?";
pagination(url);
console.log(data);
}
Frage
I'm making a call to the instagram api to get all pictures with a certain tag, the first time it works fine it shows me on console the json, but when I try to call again with the next_url to get all pictures I get this error:
XMLHttpRequest cannot load https://api.instagram.com/v1/tags/cats/media/recent?callback=jQuery18300975…092&client_id=XXXXXXXXXXXXXXXXXXX&max_tag_id=1395937138154027. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Here is the code I'm using:
var Instagram = {};
// Small object for holding important configuration data.
Instagram.Config = {
clientID: 'XXXXXXXXXXXXXXXXXXX',
apiHost: 'https://api.instagram.com'
};
(function(){
var url;
function search(tag){
generateResource(tag);
$.getJSON(url, toScreen);
}
function generateResource(tag){
url = Instagram.Config.apiHost + "/v1/tags/" + tag + "/media/recent?callback=?&client_id=" + Instagram.Config.clientID;
return url;
}
function toScreen(data){
var next_url=data.pagination.next_url;
console.log(next_url)
if(next_url!=undefined)
{
url=next_url;
pagination(url);
console.log(data);
}
}
function pagination(url)
{
$.getJSON(url, toScreen);
}
Instagram.App = {
search: search
};
}());
$(function(){
Instagram.App.search('cats');
});
Lösung
You have to add another &callback=?
for next_url
Modify like this and try it works:
if(next_url!=undefined)
{
url=next_url + "&callback=?";
pagination(url);
console.log(data);
}