4

I'm using Jquery to send JSON data to the Grooveshark API to get search results, but this is the result I get -

{"errors":[{"code":2,"message":"Method not found."}]}

This is piece of code which triggers the grooveshark API. I cannot figure out the problem with this, any help would be great.

$.ajax({
type: "POST",
    url: 'http://api.grooveshark.com/ws3.php?sig=secret_code',
    data: {
        "method":"getSongSearchResults",
        "header":{"wsKey":"secret_key"},"parameters":{"query":"megadeth hangar 18","country":"1","limit":"2","offset":""}
    },
    dataType: 'jsonp',
    crossDomain: true,
    async: false,
    success: function () {
        alert("success!"); 
    }

});
siddharthwm
  • 113
  • 1
  • 4
  • is there any error in console ? try ading error block for ajax. – Ravi Gadag Mar 04 '13 at 09:13
  • "Resource interpreted as Script but transferred with MIME type text/json: "http://api.grooveshark.com/ws3.php?sig=secret_code&callback=jQuery191029284…untry%5D=1&parameters%5Blimit%5D=2&parameters%5Boffset%5D=&_=1362385999021". jquery-1.9.1.js:8336" AND "Uncaught SyntaxError: Unexpected token :" – siddharthwm Mar 04 '13 at 09:26

1 Answers1

0

So, I'm not all the way there yet, but I wonder how you're getting the secret_code that goes on the end of your request URL.

Translating from https://github.com/fastest963/GroovesharkAPI-PHP/blob/master/gsAPI.php#L1044 it seems that the sig is NOT your secret code that you get when you apply for a public API key.

Instead it's a HMAC(md5) of the dict that you're sending in to your data parameter in your ajax call. I found https://code.google.com/p/crypto-js/#HMAC and am using that to produce the sig by passing in that dict that you're sending in as your data arg to $.ajax, and am signing it with my secret from the gs api.

I am trying to call start session, but I end up with

Object { readyState=0, status=0, statusText="error"}

which has less information, but I'm pretty sure it's not your secret that goes on that URL.

Michael
  • 2,973
  • 1
  • 27
  • 67