2013-03-04 44 views
4

我使用jQuery到JSON數據發送到的Grooveshark API來獲取搜索結果,但這是結果我得到 -的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!"); 
    } 

}); 
+0

在控制檯中是否有任何錯誤?嘗試ading錯誤塊爲ajax。 – 2013-03-04 09:13:48

+0

「將資源解釋爲腳本,但使用MIME類型text/json傳輸:」http://api.grooveshark.com/ws3.php?sig=secret_code&callback=jQuery191029284...untry%5D=1¶meters%5Blimit%5D=2¶meters%5Boffset% 5D =&_ = 1362385999021「。jquery-1.9.1.js:8336」 AND 「Uncaught SyntaxError:Unexpected token:」 – siddharthwm 2013-03-04 09:26:24

回答

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,並且使用它來生成該sig,方法是傳遞該字典中的數據,並將其作爲數據arg發送到$ .ajax,並使用我的祕密從gs api進行簽名。

我想打電話給啓動會話,但我最終

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

具有較少信息,但我敢肯定它不是你的祕密,接着該URL。