0

I would like to be able to constantly get the 10 last tracks of a user using oembed with json.

$.getJSON("http://soundcloud.com/oembed", 
          {url: "https://soundcloud.com/aviciiofficial", format: "json"},
function(data)
{
    console.log(data.html);
})

Data.html returns the soundcloud player's html code, but this player contains a track set with all the users tracks. I would like to be able to get the tracks individually (something like this: data[0].html). How can i fetch an array of all the newest tracks?

Console output:

<iframe width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Fusers%2F1861068"></iframe>

Thanks!

  • Can you show an example of the JSON response? – Mike Brant Apr 16 '13 at 00:12
  • Hey Mike, where can I get this information in the Chrome inspector? –  Apr 16 '13 at 00:15
  • In the console, I get the iframe code from this line: console.log(data.html); –  Apr 16 '13 at 00:18
  • If it is just iframe code, how do you know that data you want exists in data? You can just show console log output for `data` in your question and it might help. – Mike Brant Apr 16 '13 at 00:22
  • Ok I edited my question with the console output for console.log(data.html). But I don't understand your question. The html property returns an iframe code, but it returns the iframe code of a set of players, instead of all the individual players. My question is how can I get the inidividual players. –  Apr 16 '13 at 00:34
  • The output in your example only shows an iframe link. I don't know what you mean by a "set" of players. If the data returned does not support having that information, then you need to look at the API to see if you can get what you want. – Mike Brant Apr 16 '13 at 00:35
  • Yes, the iframe is the value of data.html. By a set of players, I mean that the iframe contains multiple tracks in it, but I guess you need to be familiar with Soundcloud to understand that. The the oEmbed documentation is not specific for Soundcloud, so it's hard to find answers on how to use it with it and Soundcloud has no documentation (or very few) on oEmbed. –  Apr 16 '13 at 00:40

1 Answers1

1

What you will have to do is to issue an API request to retrieve user’s tracks, there is no oembed endpoint that would return list of embeds.

UPD.

So, in order to show the artwork widgets you need to iterate over the array, and replace the API_URL and COLOR with each items API url and the color you want (perhaps you can set the color once for all of them actually).

'<object height="300" width="300">' + 
  '<param name="movie" value="https://player.soundcloud.com/player.swf?url={{API_URL}}&amp;color={{COLOR}}&amp;auto_play=false&amp;player_type=artwork">' +      
  '</param>' +
  '<param name="allowscriptaccess" value="always"></param>' +
  '<embed allowscriptaccess="always" width="300" height="300" ' + 
    'src="https://player.soundcloud.com/player.swf?url={{API_URL}}&amp;color={{COLOR}}&amp;auto_play=false&amp;player_type=artwork" ' +
    'type="application/x-shockwave-flash">' + 
  '</embed>' + 
'</object>';

I have described this previously in the following answer – Retrieve Soundcloud search results and embed results, only in context of HTML5 widget.

Community
  • 1
  • 1
Misha Reyzlin
  • 13,736
  • 4
  • 54
  • 63
  • Thank you for your answer Gryzzly! I will do it with the API instead. But I would like to know what is the point of using oembed if we can't fetch multiple embeds? Isn't it the same than taking the embed code manualy from a player? –  Apr 16 '13 at 14:32
  • 1
    `oembed` provides with the HTML string, API doesn't. For some people that is easier. – Misha Reyzlin Apr 16 '13 at 14:38
  • Also I want to retrieve the user's tracks, but I don't want to retrieve a signed in user's track. For example, I would like a list of someone's track, without him having to authentificate. Is that possible? –  Apr 16 '13 at 14:39
  • 1
    sure, if their sounds are public – Misha Reyzlin Apr 16 '13 at 14:41
  • Hey gryzzly, I got my tracks array that I can use with oembeds to get all the embed codes, but is there a way to retrieve the artwork widget instead of the HTML5 widget? Thank you! –  Apr 16 '13 at 16:14
  • 1
    Nope, oembed is only for HTML5 widget, please see an update to the answer to see how to do what you are willing to. – Misha Reyzlin Apr 16 '13 at 16:44
  • hah, I wanted to do exactly that, but I didn't know what to replace in the artwork widget code. Very helpful. Thanks again. –  Apr 16 '13 at 18:31