I've been able to solve it. If the resources are public, then you don't need to authenticate. Here's the code that:
- Get user URL from a wordpress custom-field
- Retrieve ID from json object
- Retrieve the latest 2 tracks and display 2 embedded players
It just need your own Client ID you can get easily by registering on soundcloud developers section, and then substitute it to {Your_ID}
// get user URL from Wordpress custom field
$sc_url = get_post_meta(get_the_id(), 'sc_url', true);
// if $sc_url is not empty, do
if (!empty($sc_url)) {
$unparsed_json = file_get_contents('https://api.soundcloud.com/resolve.json?url='.$sc_url.'&client_id={Your_ID}');
$json_object = json_decode($unparsed_json);
// retrieve the user ID from json_object
$roster_id = $json_object->{'id'};
// get last two tracks from the user and generate embed code for each tracks
$tracks_json = file_get_contents('http://api.soundcloud.com/users/'.$roster_id.'/tracks?client_id={Your_ID}&order=latest&limit=2&format=json');
$tracks = json_decode($tracks_json);
foreach ($tracks as $track){
$trackID = $track->id;
echo '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F'.$trackID.'"></iframe>';
}}
Hope it can help others :)