I am trying to create a playlist using the njasm PHP wrapper, which can be viewed here. The reason I am using this wrapper is because it allows for direct user login. And fo
Thanks for using my library.
playlists at soundcloud are tricky. lately I've updated the library and tested what you need in the latest version.
UPDATE 28-04-2015: you'll need the latest 2.2.1 stable version or higher to use the below example code.
Note: version 3.x.x is still under heavy development, example below is for 2.x.x
Note: take in considerations that the Request object was changed in the way the requests are made to soundcloud further tests are needed before i recommend to use that version in production. (also that's why I still didn't tag it as stable version)
With this in mind, do this:
1) Download the latest MASTER 2.2.1 tag, or higher (If you installed it via composer update you composer.json to "njasm/soundcloud": "dev-master"
"njasm/soundcloud": "2.2.1"
and run composer update in a development environment.) You'll need any version above 2.2.0 stable but not 3.0.x since it's not stable yet.
after that try this code:
// initialize Soundcloud
// auth via User Credential Flow
$soundcloud = new \Njasm\Soundcloud\SoundcloudFacade(
$clientID, $clientSecret
);
$soundcloud->userCredentials("user@email.com", "user_password");
// build playlist main array
$playlistData = array(
"playlist" => array(
"title" => "My2 great Title Playlist!",
"sharing" => "public", // or private
)
);
//create playlist at soundcloud and grab the response
$response = $soundcloud->post('/playlists', $playlistData)->request();
// build tracks array
$tracks = array(
"playlist" => array(
"tracks" => array(
array("id" => 29720509), // Connect the Dots
array("id" => 26057359) // Forgotten Values
)
)
);
// put tracks into playlist
$response = $soundcloud->put(
'/playlists/' . $response->bodyObject()->id,
$tracks
)->request();
var_dump($response->bodyArray());
die();
This Should will work.
Take in consideration also that every time you "PUT" a request to a playlist you have to build the tracks array with all the track IDS that you want in that playlist/set, soundcloud will erase all tracks and insert the new ones.
I Would like to ask you, if you find any issues with the library to report them in the github issues page.
Thanks and have fun!