Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Set With Soundcloud's API

I'm using Javascript to create a web app with Soundcloud's API for my portfolio. At my current stage I need to be able to create a new set (aka playlist). I was using the sample code from Soundcloud's docs:

SC.connect(function() {
  var tracks = [22448500, 21928809].map(function(id) { return { id: id } });
  SC.post('/playlists', {
    playlist: { title: 'My Playlist', tracks: tracks }
  });
}); 

But I'm getting a 422 error:

Unprocessable Entity - The request looks alright, but one or more of the parameters looks a little screwy. It's possible that you sent data in the wrong format (e.g. an array where we expected a string).

But it does not look like anything's missing.

like image 251
brooklynsweb Avatar asked Jul 12 '15 21:07

brooklynsweb


People also ask

What can you do with SoundCloud API?

Our API gives you the ability to upload, manage and share tracks. Your app can take an audio file and upload it to a user's SoundCloud account. You can also manage metadata (including tags) or add the track to playlists.

Can I use SoundCloud API?

To access the SoundCloud® API, you will first need to register your app at https://soundcloud.com/you/apps using your SoundCloud® account. When you've done that, we'll issue you with a client ID and client secret. Your client ID is required for all calls to the SoundCloud® API.

How do I use SoundCloud API on Android?

You need to get your client_id and client_secret by registering your app here. After you have obtained that, you can start using the API. Basically, most of the calls will look like this one: final SoundCloud api = new SoundCloud.

Does SoundCloud use JavaScript?

The SDKs will make it easier to access the SoundCloud API on your framework of choice. We officially provide and support only JavaScript. All other SDKs (Ruby, Python) are supported by third-party developers.


1 Answers

The call to the SoundCloud API requires a callback function in addition to the playlist title and tracks. Your code should look like this:

SC.connect(function() {
  var tracks = [22448500, 21928809].map(function(id) { return { id: id } });
  SC.post('/playlists', {
    playlist: { title: 'My Playlist', tracks: tracks }, function(response){
      console.log(response)
    }
  });
});

Their example is, unfortunately, wrong.

like image 174
Cory Ribson Avatar answered Sep 18 '22 05:09

Cory Ribson