...

View Full Version : Spotify request.



Alienn
03-19-2013, 01:54 PM
Hello all,

Im trying to get make a request to the spotify servers with an .Ajax call.
But all I am getting is a 400 Bad Request error in my console.
Did I missed something? Like script src in my html file?

Thanks in advance.


Html code:


<html>
<head>
<title>Test</title>
<meta charset=utf-8>
<script type="text/javascript" src="jquery-1.9.1.js"> </script>
<script type="text/javascript" src="js/main.js"> </script>

</head>
<body>
<h1>Test</h1>

</body>
</html>

Js code:




$(document).ready(init);

function init()

{

$.ajax({
type:"GET",
dataType:"json",
cache:false,
url: "http://ws.spotify.com/search/1/album?q=foo",
success:getInfo


});



}



function getInfo(data) {



$.each(data.data, function (i, item) {
//





});

}

devnull69
03-19-2013, 02:51 PM
The Spotify API requires to specify the format as .json if you want to use JSON, otherwise you will get an XML response



url : 'http://ws.spotify.com/search/1/album.json?q=foo'

Alienn
03-19-2013, 03:58 PM
The Spotify API requires to specify the format as .json if you want to use JSON, otherwise you will get an XML response



url : 'http://ws.spotify.com/search/1/album.json?q=foo'


Tried it, but still the same error:


GET http://ws.spotify.com/search/1/album.json?q=foo&_=1363705060815

400 Bad Request

xelawho
03-19-2013, 04:35 PM
you can just put the url into your address bar to see if it works - this for example gets something, I don't know if it's what you want...
http://ws.spotify.com/search/1/album.json?q=foo#1363705060815

devnull69
03-19-2013, 04:46 PM
The problem is the cache: false part. It will append a random parameter "_" to the query which will result in 400 BAD REQUEST coming from spotify.

Just remove the cache parameter and it will work.

Alienn
03-19-2013, 08:55 PM
The problem is the cache: false part. It will append a random parameter "_" to the query which will result in 400 BAD REQUEST coming from spotify.

Just remove the cache parameter and it will work.

That worked thanks!

Alienn
03-20-2013, 06:47 PM
I have another question.
Does anyone know if there is a url to get json information about a random track? It would really help me out.

rnd me
03-20-2013, 07:32 PM
I have another question.
Does anyone know if there is a url to get json information about a random track? It would really help me out.

just search from a random letter (a-z) and then grab a random item from the returned list.


for example, this url returns 100 albums, you can grab one of them for a random pick:

http://ws.spotify.com/search/1/album.json?q=a

Alienn
03-20-2013, 07:52 PM
just search from a random letter (a-z) and then grab a random item from the returned list.


for example, this url returns 100 albums, you can grab one of them for a random pick:

http://ws.spotify.com/search/1/album.json?q=a

Ah of course, thanks for your help.

Alienn
03-21-2013, 04:13 PM
It finally worked to show random songs on my website, however I want my spotify player to automatic start by refreshing the page. Is this possible with the spotify iframe?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum