Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AJAX Basics (retiring) AJAX and APIs Review the Flickr API

Robert Gage-Smith
Robert Gage-Smith
13,977 Points

Finish this code to retrieve a JSON formatted version of the Flickr Public Photo Feed:

Hi!, I'm stuck with this single question. I'm adding '?jsoncallback=?' after .gne, exactly as in the vid tutorial but I keep getting a "bummer|" message.. What am I missing?? Thanks!

8 Answers

curtis is correct, you need the format parameter. The jsoncallback parameter is for getting a JSON-P response back from the API, which is similar to JSON but expects a callback function to be run on the response.

Robert Gage-Smith
Robert Gage-Smith
13,977 Points

Ah, thanks, that clears that up.

Robert Gage-Smith, if you could select a best answer to close off this question, that'd be great!

"?format=json" is correct

The Flickr API can return its response in a number of different formats, so you need to specify the format parameter (sent as a query string variable in the URL) with a value of json to get the response back in JSON format, as specified in the quiz question.

The jsoncallback parameter is used for JSON-P responses, and the value would be the name of a function (that you would have to define beforehand) that would be 'wrapped' around the response so that it will run it with the response data.

For example, if you had a function called logMe that just logged the passed in data to the console, like so:

function logMe(data) {
  console.log(data);
}

Then you could send a request to the follow URL: https://www.flickr.com/services/rest/?method=flickr.test.echo&format=json&api_key=fd67e1080666203b0ae2912246ca7a48&jsoncallback=logMe

And you would get a response similar to the following:

logMe (
  {
    "method": {
      "_content": "flickr.test.echo"
    },
    "format": {
      "_content": "json"
    },
    "api_key": {
      "_content": "fd67e1080666203b0ae2912246ca7a48"
    },
    "jsoncallback": {
      "_content": "logMe"
    },
    "stat": "ok"
  }
)

Which would log the response object (between the first and last curly braces) to the (browser) console like so:

▼ Object {method: Object, format: Object, api_key: Object, jsoncallback: Object, stat: "ok"}
  ▼ api_key: Object
    _content: "fd67e1080666203b0ae2912246ca7a48"
    ►__proto__: Object
  ▼ format: Object
    _content: "json"
    ►__proto__: Object
  ▼ jsoncallback: Object
    _content: "logMe"
    ►__proto__: Object
  ▼ method: Object
    _content: "flickr.test.echo"
    ►__proto__: Object
  stat: "ok"
  ►__proto__: Object

Hello there,

You just need to put in the blank the below info:

?format=json

Thanks, Kazim Noori

I do not understand your answer; can you please explain it a little more?

There's a good chance the Flickr API has been updated since this question and answer were posted. If you find the new API syntax for receiving a JSON response (it might be the default now), then please share it here!