Updates to the SoundCloud AS3 API

During the last week I made some improvements to the SoundCloud AS3 API library:

  • Full ASDoc documentation is now available online
  • Uploaded an example file for Flash CS4
  • API is now prepared for scenarios where you want to automatically get an access token after authentication (I’ll do an extra post on this in the next days)
  • Added support for requests to public resources without having to authenticate first


I should say a few words about the last point: If you want to build a simple audio player app like Citysounds (check it out, great stuff!) that only accesses public resources, chances are you don’t have to deal with OAuth authentication at all.

For example, the code to access the public tracks of  a specific SoundCloud user looks like this:

var scClient:SoundcloudClient = new SoundcloudClient("yourConsumerKey", "yourConsumerSecret");

var delegate:SoundcloudDelegate = scClient.sendRequest("users/anyUserName/tracks", "GET");

delegate.addEventListener(SoundcloudEvent.REQUEST_COMPLETE, requestCompleteHandler);

protected function requestCompleteHandler(event:SoundcloudEvent):void
{
  var trackList:XML = event.data as XML;

  trace(trackList);
}

This will give you a list of tracks in XML format with all properties like track title, URL and so on. You can then pick a track from the list and start playing the MP3 with the Sound class. Yes, it’s that simple! ;)

But as soon as you want to access private tracks or want to do write operations like  updating a user profile or uploading a track, you’ll need to go through the OAuth authentication process. Check the Quickstart Tutorial to see how this works.

UPDATE (05/17/2010)

SoundCloud is about to change the policy for accessing public resources via their API. They will soon require a consumer key and secret for all calls, no matter whether you use OAuth or not. They had already implemented that on the sandbox server on friday, pulled it back today, but plan to roll it out again on sandbox later this week. Anyway, it looks like you should prepare your app for this change as soon as possible. I just changed the example above to include “yourConsumerKey” and “yourConsumerSecret” in the constructor of the SoundcloudClient.

The bottom line is that you need to register your app with SoundCloud in any case now. But you don’t need to get an update of the Soundcloud-AS3-API files. And if you’re using OAuth, nothing changes at all for you.

You can find a detailed guide on how to register your app and use the app key and secret codes in the Github-Wiki (you can skip the authentication steps 4 – 6 if you don’t use OAuth).

Read more about this update in the SoundCloud API Google Group

12 thoughts on “Updates to the SoundCloud AS3 API”

  1. Hi! I’ve been trying to create a flash based uploader for Soundcloud for my Rails application. I’ve run into an issue that perhaps you can assist with – first, I’m hitting their API directly so I can avoid having to upload first to my server and then push to SC. The problem I’ve encountered is that even after a successful upload, I am unable to retrieve the response Content-Location header data. Is this even possible? I need to get this link so that i can store it in the app…

  2. I’m trying to just use the public method to grab some tracks from my user account. So I’m not using any authorisation.

    I’m using essentially the same code snippet as the one you provided above, however I am getting a Error #2032: Stream Error. Can you advise as to why this might be happening?

  3. @Sam
    check if you get a valid response when you copy the URL in your browser address bar, to make sure that you use the correct URL
    e.g. http://soundcloud.com/users/yourUserName/tracks
    If your browser displays a blank page, check the source code of the page because the browser might not display XML code.
    If that works but you still get the error in Flash, please post your code here or send it to me via email (dori@nroy.de)

  4. @Dorian
    The URL works fine, it brings up the correct XML page. I get the following error in flash:

    http://api.sandbox-soundcloud.com/users/***/tracks.xml?oauth_consumer_key=&oauth_nonce=***&oauth_signature=***&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1274096951

    NB – I’m not sure how important the information is in that URL so just to be certain I starred it out. When I attempt to go that URL I get an XML page that says 401-Unauthorized.

    Any ideas what might be going wrong?

  5. @Sam
    Just found out that SoundCloud has rolled out a new authentication policy on their sandbox-server on friday. They’re not accepting calls to public resources without a consumer key anymore. The production server still works without a key though. So if you change your client to use the production server, everything should be fine. Just set the fourth argument to false:
    new SoundcloudClient(“”,””,null,false);

    But to be ready when they roll this out on the live system, you should register your app now and get a consumer key. Read more about it here:
    http://groups.google.com/group/soundcloudapi/browse_thread/thread/a6d05b7bf4d64a3f/bcdb595d73bf1ee3

    Thanks for pointing this out! I’ll update the post now.

  6. @Dorian
    Thanks for the update, it explains a lot. I’ve registered my application, but I still can’t connect to the Sandbox server, even with the consumer key and consumer secret supplied. Do I need to register my application on the sandbox as well? I’m not quite sure the difference between http://www.soundcloud.com and http://sandbox-soundcloud.com/ – can you clear it up?

    Thanks.

  7. After downloading everything I am getting stuck at 1150: The protected attribute can only be used on class property definitions.

  8. I want to know if i can record my sets when I am djing , with scup and if yes , how to do it.
    Thank you

    Ro

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>