juan garcia
juan garcia

Reputation: 21

API call using getJSON not working

I'm trying to modify the flickr example from: http://api.jquery.com/jquery.getjson/ to use the Sqoot API instead. I'm using this example to learn about jquery. Can somebody please tell me why it works with flickr but not sqoot?

I changed my api key to MYKEY, but they will give you one instantly by just providing an email and making a password.

Thanks.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>SQOOT</title>
  <style>
    img {
      height: 100px;
      float: left;
    }
  </style>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
  <div id="images"></div>
  <div id="titles"></div>
  <div id="images2"></div>
  <script>
    (function() {
      var SqootAPI = "http://api.sqoot.com/v2/deals?api_key=MYKEY&callback=?";
      $.getJSON( SqootAPI, {
        location: "miami"
      })
      .done(function( data ) {
        $.each( data.deals, function( i, item ) {
          $( "<img>" ).attr( "src", item.deal.image_url ).appendTo( "#images" );
          if ( i === 3 ) {
            return false;
          }
        });
      });
    })();
  </script>
</body>
</html>

Upvotes: 2

Views: 244

Answers (1)

jvecsei
jvecsei

Reputation: 1993

Actually they're return a JSON String and not a JSONP return value.

It should look like this:

yourCallbackFunction({Object})

But they're just return JSON data:

{ result: [ ] }

That's why you're getting a message in your console:

SyntaxError: missing ; before statement

And if you dont use a callback function you get the same origin policy ofc.

You should maybe contact the support to tell them you that there's something wrong with their API.

edit:

http://api.sqoot.com/v2/deals?api_key=YourKey&callback=pickles

http://docs.sqoot.com/v2/overview.html

There you can also see that it doesn't return the expected value they wrote in their documentation ( pickles({ "deals": [] }) ) which would be valid jsonp.

Upvotes: 1

Related Questions