Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Spotify request.

    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:


    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:

    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) {
            //
    
    
    
    
    
        });
    
    }
    Last edited by Alienn; 03-19-2013 at 04:04 PM.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    The Spotify API requires to specify the format as .json if you want to use JSON, otherwise you will get an XML response

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

  • #3
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by devnull69 View Post
    The Spotify API requires to specify the format as .json if you want to use JSON, otherwise you will get an XML response

    Code:
    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...=1363705060815

    400 Bad Request

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,913
    Thanks
    56
    Thanked 545 Times in 542 Posts
    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...#1363705060815

  • #5
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    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.

  • #6
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by devnull69 View Post
    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!

  • #7
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,294
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Quote Originally Posted by Alienn View Post
    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
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #9
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rnd me View Post
    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.

  • #10
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •