1

Please would someone give me an example of how to call yboss (v2) using jquery. I've tried using getJSON and $.ajax methods passing the correct oauth values and signature but neither methods call the callback function. The same code worked fine with v1 of boss.

Here's an example of the url (requestStr) I pass to ajax:

    http://yboss.yahooapis.com/ysearch/web?callback=?&count=10&oauth_consumer_key=dj0yJmk9SFUzQno3ZnUwMHBaJmQ9WVdrOWNXRkRaa1Z2Tm1zbWNHbzlOek01TVRJeU1UWXkmcz1jb25zdW1lcnNlY3JldCZ4PWNk&oauth_nonce=7887075&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1317994276&oauth_version=1.0&q=horse&start=0&oauth_signature=lFVXgxkq79Tp5E5QeyEHdOfbASg=

When pasted into a browser (chrome) this returns the results expected. A payment account for using Yahoo Boss has been setup successfully in order to make calls to this api.

Thanks,

Rob

    $.getJSON(requestStr, function (response) {

    // never gets here

    });

    this doesn't work either:

    $.ajax({
      type: 'GET',
      url: requestStr,
      dataType: 'jsonp',
      success: function (response) {
      // never gets here
      }
    });

1 Answers1

1

You're URL doesn't include a callback GET parameter. $.getJSON only requests JSONP if it finds that in the URL, so that's why that doesn't work. $.ajax, however, will supposedly add it to the URL if you specify the dataType as "jsonp", according to the jQuery docs. However, I see examples in the wild that include the callback in the URL regardless of specifying "jsonp" as the dataType. So, give it a shot.

As @Eonasdan suggested, check the responses you're getting in your console. If they're red, that means there's some sort of error, and in 99.9% of cases like these, it's due to same-origin policy.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • According to JQuery docs "If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead.". My Url does have this. I assumed that because this is a cross-domain access I would need JSONP. – Robert Northen Oct 07 '11 at 15:54
  • Sorry. Looked at that URL 50 times and didn't see the callback parameter until just now. Still, have you examined the response you're getting in the console? – Chris Pratt Oct 07 '11 at 16:16
  • Yes, I'm getting a 401 (Authorisation Required). But I don't know how to fix this. Thanks. – Robert Northen Oct 07 '11 at 16:36
  • Would you happen to be developing locally? Seems Yahoo OAuth doesn't play nice with local development. See: http://stackoverflow.com/questions/3623208/how-can-i-get-yahoo-oauth-to-work-when-i-develop-locally-when-my-local-domain-is. One user suggests setting your app as a standalone app will allow it to work on your machine for development. – Chris Pratt Oct 07 '11 at 16:53
  • Seen that post and I did create another app for working locally. Still getting the same result. How should the oauth_signature be encoded? Occurred to me that this could be the problem. – Robert Northen Oct 07 '11 at 16:57
  • I need to use a Cross Domain call therefore I add callback=? to the url. However jquery modifies the url and changes callback=? to callback=somethingelse and appends some other value to the end of the url. Modifying the url invalidates the oauth signature and stops the request from authenticating. Does this sound right? How do I fix this? – Robert Northen Oct 07 '11 at 20:29
  • That's normal procedure. jQuery tells you to use `?` because behind the scenes it's taking care of the callback. However, it shouldn't be mussing around with the URL other than to simply replace the `?`, so I'm not sure why it would be invalidating your oauth sig. – Chris Pratt Oct 11 '11 at 14:18
  • You can effectively supplant jQuery's callback functionality with your own by using `$.ajax` with options: `{ jsonp:false, jsonpCallback: "myCallbackFunction" }`. Then, simply specify the callback in the URL as if you were using straight javascript. – Chris Pratt Oct 11 '11 at 14:23