0

I am trying to get the last couple of photos posted by a certain user.

On this site I've found many answers saying that it is possible to do that without an authentication token (for example, How can I get a user's media from Instagram without authenticating as a user?).

Whenever I open https://api.instagram.com/v1/users/search?q=cocacola&client_id=5c314c67157f4585ba3041281540c59b on my browser, I get a valid json response. But when I perform a get request on a javascript in my site, it fails.

EDIT: For future reference, the problem is related to cross domain requests.

Community
  • 1
  • 1
ig343
  • 277
  • 1
  • 3
  • 17

1 Answers1

1

You need to use jsonp, e.g:

$.ajax({
    url: "https://api.instagram.com/v1/users/search?q=cocacola&client_id=5c314c67157f4585ba3041281540c59b", 
    // Tell jQuery we're expecting JSONP
    dataType: "jsonp",
    success: function( response ) {
        console.log( response ); // server response
    }
});

-DEMO-

A. Wolff
  • 74,033
  • 9
  • 94
  • 155