Search code examples
javascriptjqueryapiflickr

Using getJSON to access Flickr data


I'm trying to access the JSON data for this user and write the id of the person using this code:

   <!DOCTYPE html>
<html>
<head>
<script type="text/javascript">

</script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript">
API_KEY = 'YOUR_API_KEY';

$.getJSON('https://www.flickr.com/services/rest/?method=flickr.people.getPhotos&api_key=' + API_KEY + '&user_id=22694125@N02&format=json&jsoncallback=?', function(results){
      document.body.innerHTML = JSON.stringify(results.photos.photo[6].id);
  });</script>

</head>
<body>

</body>
</html>

For some reason, it doesn't return anything. Help?


Solution

  • Based on what I've read I think you need to something like this:

    $.ajax(
    {
        url: "https://www.flickr.com/services/rest/?method=flickr.people.getPhotos&api_key=[APIKEY]&user_id=22694125@N02&format=json&jsoncallback=?",
        type: "GET",
        cache: true,
        dataType: 'jsonp',
        success: function(data) 
        {
            console.log(data);
        }
    });
    

    I believe the calls have to be JSONP (not JSON).