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.

This entry was posted in Soundcloud and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

13 Comments

  1. Posted February 9, 2010 at 10:39 | Permalink

    Wicked! i will plug this into my site as soon as ive got a day off ++

  2. Posted March 22, 2010 at 18:11 | Permalink

    Hi nice work… i will check it on github! :)

  3. Posted March 22, 2010 at 18:12 | Permalink

    Hi nice work… i will check it on github! :)

    Upps wrong link, sry for double posting! :)

  4. Marc Widmer
    Posted April 21, 2010 at 17:45 | Permalink

    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:
    http://media.sandbox-soundcloud.com/stream/****

    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

  5. Dorian
    Posted April 21, 2010 at 19:33 | Permalink

    @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:
    http://dasflash.com/soundcloud-as3-api/asdoc/com/dasflash/soundcloud/as3api/SoundcloudClient.html#SoundcloudClient()

  6. rumori
    Posted August 22, 2010 at 02:34 | Permalink

    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.

    Thanks

  7. rumori
    Posted August 22, 2010 at 02:45 | Permalink

    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);

    Cheers.

  8. dub
    Posted January 7, 2011 at 10:20 | Permalink

    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?

    Thanks

    dub

  9. Dorian
    Posted January 14, 2011 at 19:04 | Permalink

    @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

  10. Posted February 9, 2011 at 14:20 | Permalink

    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 = “http://api.soundcloud.com/me/followings/tracks?consumer_key=[my consumer key]“;

    but i get unauthorized access.

    what am I doing wrong?

  11. Posted May 3, 2011 at 18:05 | Permalink

    Hi

    I’m trying the advanced sample and I keep getting a 401 error:

    POST http://api.sandbox-soundcloud.com/oauth/request_token [HTTP/1.1 401 Unauthorized 243ms]

    I have created a sandbox account and am using my OAuth1 key and secret and I’m not sure how to debug?

  12. Posted June 21, 2011 at 18:04 | Permalink

    Is there a way to connect in an air application without opening a browser window?

  13. Dorian
    Posted June 21, 2011 at 18:46 | Permalink

    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.

Post a Comment

Your email is never published nor shared. 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>