4

我正在使用 Jquery 将 JSON 数据发送到 Grooveshark API 以获取搜索结果,但这是我得到的结果 -

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

这是触发grooveshark API的一段代码。我无法弄清楚这个问题,任何帮助都会很棒。

$.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!"); 
    }

});
4

1 回答 1

0

所以,我还没有走到那一步,但我想知道你是如何获得请求 URL 末尾的 secret_code 的。

https://github.com/fastest963/GroovesharkAPI-PHP/blob/master/gsAPI.php#L1044翻译,似乎 sig 不是您在申请公共 API 密钥时获得的密码。

相反,它是您在 ajax 调用中发送到数据参数的字典的 HMAC(md5)。我找到了https://code.google.com/p/crypto-js/#HMAC并使用它通过将您作为数据 arg 发送到 $.ajax 的 dict 传递来生成 sig,并且我用我来自 gs api 的秘密签名。

我正在尝试调用开始会话,但最终得到

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

其中信息较少,但我很确定该 URL 上的内容不是您的秘密。

于 2013-03-07T18:09:31.700 回答