Track list of Soundcloud tracks without authentication

I would like to pull a specific user tracklist and display it. Now I'm going to do this, but I always need to connect (by clicking the link), is there a way for me to eliminate this step or a way to always be authenticated. I tried this on the soundcloud api but no success and I don't understand why authentication is required when accessing public data.

<?php
session_start();
//session_destroy();
require 'Soundcloud.php';

$soundcloud = new Services_Soundcloud('MY_CLIENT_ID', 'MY_SECRET', 'http://www.ericmlt.com/MarcKane/soundcloud/');
$soundcloud->setDevelopment(FALSE);

$authURL = $soundcloud->getAuthorizeUrl();

echo "<a href='$authURL'>Connect to Soundcloud</a>";

//Attempt to get token from Session first
//Set the token otherwise..

try {

    $accessToken = $soundcloud->accessToken($_GET['code']);
    if(!isset($_SESSION['token'])){
    $_SESSION['token'] = $accessToken['access_token'] ;
}  else {
    $soundcloud->setAccessToken($_SESSION['token']);
}
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
    exit($e->getMessage());
}
try {
    $tracks = json_decode($soundcloud->get('tracks', array('user_id' => '857348')), TRUE);
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
    exit($e->getMessage());
}

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>';
}
?>

      

+3


source to share


1 answer


You can simply create a list of such tracks:

echo '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http://api.soundcloud.com/users/857348"></iframe>';

      

Otherwise, if you need to get a list of tracks and create a widget for each one (not recommended), you can go with this (note that I don't write much PHP, but the idea is to issue an HTTP GET to the next Url):



$tracks_json = file_get_contents('http://api.soundcloud.com/users/857348/tracks.json?client_id=YOUR_CLIENT_ID');
$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>';
}

      

You don't need to authenticate here.

+3


source







All Articles