New Tutorial and Updates for the SoundCloud AS3 API

I just wrote a new tutorial for the SoundCloud AS3 API, “How to Go Through OAuth Authentication in a Single Browser Window”. This tutorial explains how to set up a web-based Flash application in a way that the user stays in the same browser window during the OAuth authentication and does not need to copy /paste the verification code manually.

For example, this could be a good solution for a music player that lets users listen to their favourite SoundCloud playlists. It works without any backend services by using some Javascript and the Local Shared Object aka “Flash Cookie”. The tutorial requires some basic knowledge of how to pass variables to Flash, a little bit of JavaScript and intermediate AS3 skills.

The basic concept of the solution applies to every other API using OAuth 1.0a as well, so you also might find this tutorial interesting if you use Flash clients to access the API’s of Google Apps, Twitter or MySpace.

You can find the tutorial on the GitHub wiki pages of the SoundCloud AS3 API. It includes the full code of an example application made with Flash CS4. If you have questions or comments regarding this tutorial, please leave a comment here on this post.

Recently I have also corrected an error in the documentation of the AS3 API: You can’t compile the sources without the Flex framework, because the OAuth library that I use needs some Flex utility classes. I wasn’t aware of this dependency before (thanks to Marc for giving me the hint!). So if you want to include the SoundCloud API in a Flash CS4 project you have to use the pre-compiled SWC file instead of the .as sources. I have updated the docs and Flash example files accordingly.

The AS3 API repository on GitHub was apparently corrupted after the last update, which seems to have been caused by a known bug of the egit plugin for Eclipse (thanks to Matas for pointing this out 😉 I have just fixed the repo and use SmartGit now to push updates to GitHub. I hope this will prevent such issues in the future.

14 thoughts on “New Tutorial and Updates for the SoundCloud AS3 API

  1. Hi There

    Thans for the API first. I have question which i could not solve so far.

    I am currently implementing a custom flash player for public files of a specific user. I need to do it in flash, but actually i do not need auth, as only public content is used.

    is it possible that:

    var scClient:SoundcloudClient = new SoundcloudClient();

    is always in sandbox mode? because the retrieved stream-url looks like this:****

    How can i connect as simple as described but in live mode, not sandbox.

    Any help would be really apreciated.

    Thanks a lot, beside this everything works really nice
    Best M

  2. @Marc
    You’re right, the API uses the sandbox by default. That’s just to avoid that you accidentally mess up your live data when playing around with the API. To access the live system, you have to set the 4th argument in the constructor to “true”. So if you don’t use OAuth, that would be:
    var scClient:SoundcloudClient = new SoundcloudClient(“”, “”, null, true);
    See the docs for a reference for all parameters:

  3. Hello, I’ve been messing with the library but couldn’t edit favorites, I always get Unauthorized 401 error, altought “me” request works as expected.

    Here’s what I’m trying to do:

    var delegate:SoundcloudDelegate = scClient.sendRequest(‘me/favorites/3371381’ URLRequestMethod.GET);
    delegate.addEventListener(SoundcloudEvent.REQUEST_COMPLETE, favoriteComplete);

    I’m using the production server, didn’t took the time to register twice etc.
    Can you post a working snippet, I guess I’m missing something obvious here.


  4. Funny how problems seem to get solved just after asking somebody 🙂
    Here’s the solution:

    var delegate:SoundcloudDelegate = scClient.sendRequest(‘me/favorites/3371381’, URLRequestMethod.POST, {_method: ‘PUT’});
    delegate.addEventListener(SoundcloudEvent.REQUEST_COMPLETE, favoriteComplete);


  5. Hi,

    Thanks a lot for sharing this tool. I’m attempting to use the flex example but I am constantly getting an Unhandled Http status error when attempting to get the access token. I am certain that my consumer key and secret key are correct.

    Have you any idea what might be the cause?

    In addition I am curious to know could you code be modified to use only an access token if that token was provided to my swf by the html page embedding it?



  6. @dub Maybe you’re using the sandbox server with an account for the live server or vice versa. You need to create an extra account for each SoundCloud server

  7. awesome! I have it working. for connecting, but now i am looking for examples on how to implement specific calls. Specifically how to return a json feed of incoming tracks.

    can you point me to specific documentation? I tried loading this url to get the feed:

    _urlVar = “[my consumer key]”;

    but i get unauthorized access.

    what am I doing wrong?

    1. Actually, the whole point of OAuth is that you can’t do that 😉

      You could only try to load the login form in a HTML view inside your app and then grab the security code from the URL of the returned page.

      But honestly, I wouldn’t enter my password in an app like this because there’s no way to know that you’re showing me the actual SoundCloud login form and not trying to phish my password. In the browser, you see the URL of the site and know that you’re sending your password to SoundCloud.

  8. Greetings,
    Is there anyway to update /me profile with POST method? Cause i have been trying to do it and i always get:

    error: Unauthorized
    error: Error #2032: Stream Error. URL:***.json

    But i think my code is correct as i am using:

    params[“user[description]”] = “This is just a Test”;

    var delegate:SoundcloudDelegate = scClient.sendRequest(“me?consumer_key=***”, URLRequestMethod.POST, params);

    And after some search i found some people solving the Unauthorized problem by changing POST to PUT, but flash wont support PUT :

Leave a Reply

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