Packagecom.dasflash.soundcloud.as3api
Classpublic class SoundcloudClient
InheritanceSoundcloudClient Inheritance flash.events.EventDispatcher

Central class of the Soundcloud API wrapper for AS3.

Create an instance of this class and call its authentication methods to connect your app with the Soundcloud REST API. Once you're authenticated you can call every resource through the sendRequest method.

You can also call public resources without going through the authentication process.

View the examples

See also

http://github.com/dasflash/Soundcloud-AS3-API
http://api.soundcloud.com/api


Public Properties
 PropertyDefined By
  responseFormat : String
Sets the format of the server response (XML or JSON).
SoundcloudClient
  useOAuth1_0 : Boolean
Set to true for legacy OAuth 1.0 authentication (not recommended).
SoundcloudClient
  useSandBox : Boolean
Determines whether the SoundCloud sandbox system is used (recommended for testing) or the live service.
SoundcloudClient
Protected Properties
 PropertyDefined By
  accessToken : OAuthToken
SoundcloudClient
  callbackURL : String
SoundcloudClient
  consumer : OAuthConsumer
SoundcloudClient
  consumerKey : String
SoundcloudClient
  consumerSecret : String
SoundcloudClient
  requestToken : OAuthToken
SoundcloudClient
Public Methods
 MethodDefined By
  
SoundcloudClient(consumerKey:String, consumerSecret:String, accessToken:OAuthToken = null, useSandbox:Boolean = true, responseFormat:String = xml)
Creates a Soundcloud API client.
SoundcloudClient
  
authorizeUser(targetWindow:String = _blank):void
Opens authorization page to grant data access for your app.
SoundcloudClient
  
getAccessToken(verificationCode:String = null, externalRequestToken:OAuthToken = null):SoundcloudDelegate
Retrieves the access token.
SoundcloudClient
  
getRequestToken(callbackURL:String = null):SoundcloudDelegate
Retrieves a request token.
SoundcloudClient
  
sendRequest(resource:String, method:String, data:Object = null):SoundcloudDelegate
Make a request to the API.
SoundcloudClient
Protected Methods
 MethodDefined By
  
createDelegate(resource:String, method:String, data:Object = null, responseFormat:String, dataFormat:String, requestToken:OAuthToken = null):SoundcloudDelegate
Sends the actual API call.
SoundcloudClient
Events
 Event Summary Defined By
  Dispatched when the client receives an access token after getAccessToken has been called.SoundcloudClient
  Dispatched when the request of getAccessToken has failed.SoundcloudClient
  Dispatched when the client receives a request token after getRequestToken has been called.SoundcloudClient
  Dispatched when the request of getRequestToken has failed.SoundcloudClient
Protected Constants
 ConstantDefined By
  accessTokenResource : String = oauth/access_token
SoundcloudClient
  requestTokenResource : String = oauth/request_token
SoundcloudClient
Property Detail
accessTokenproperty
protected var accessToken:OAuthToken

callbackURLproperty 
protected var callbackURL:String

consumerproperty 
protected var consumer:OAuthConsumer

consumerKeyproperty 
protected var consumerKey:String

consumerSecretproperty 
protected var consumerSecret:String

requestTokenproperty 
protected var requestToken:OAuthToken

responseFormatproperty 
responseFormat:String

Sets the format of the server response (XML or JSON). The value must be SoundcloudResponseFormat.JSON, .XML or an empty String (default) which will also return XML.


Implementation
    public function get responseFormat():String
    public function set responseFormat(value:String):void
useOAuth1_0property 
useOAuth1_0:Boolean

Set to true for legacy OAuth 1.0 authentication (not recommended).


Implementation
    public function get useOAuth1_0():Boolean
    public function set useOAuth1_0(value:Boolean):void
useSandBoxproperty 
useSandBox:Boolean

Determines whether the SoundCloud sandbox system is used (recommended for testing) or the live service.


Implementation
    public function get useSandBox():Boolean
    public function set useSandBox(value:Boolean):void
Constructor Detail
SoundcloudClient()Constructor
public function SoundcloudClient(consumerKey:String, consumerSecret:String, accessToken:OAuthToken = null, useSandbox:Boolean = true, responseFormat:String = xml)

Creates a Soundcloud API client.

If no consumerKey and consumerSecret are passed to this function you can only access public resources (e.g. "tracks") and cannot retrieve a request token. Else if you have consumerKey and consumerSecret but no accessToken, you can only call public resources and getRequestToken.

Parameters
consumerKey:String — The consumer key you receive when registering your app with Soundcloud (optional).
 
consumerSecret:String — The consumer secret you receive when registering your app with Soundcloud (optional).
 
accessToken:OAuthToken (default = null) — A previously retrieved access token for the current user (optional).
 
useSandbox:Boolean (default = true) — Switch between the Soundcloud live system (false) and the developer. sandbox system (true, default)
 
responseFormat:String (default = xml) — "json" or "xml" (default).
Method Detail
authorizeUser()method
public function authorizeUser(targetWindow:String = _blank):void

Opens authorization page to grant data access for your app.

Parameters

targetWindow:String (default = _blank) — (optional) Target window name, defaults to "_blank". Use "_self" to open the authentication page in the current window

createDelegate()method 
protected function createDelegate(resource:String, method:String, data:Object = null, responseFormat:String, dataFormat:String, requestToken:OAuthToken = null):SoundcloudDelegate

Sends the actual API call.

Parameters

resource:String — The resource locator, e.g. "user/myUserId/tracks"
 
method:String — GET, POST, PUT or DELETE. Note that FlashPlayer only supports GET and POST as of this writing. AIR supports all four methods.
 
data:Object (default = null) — (optional) The data to be sent. This can be a generic object containing request parameters as key/value pairs or a XML object
 
responseFormat:String — (optional) Tells Soundcloud whether to render response as JSON or XML. Value must be SoundcloudResponseFormat.JSON, .XML or an empty String (default) which will also return XML
 
dataFormat:String — (optional) "binary", "text" (default) or "variables"
 
requestToken:OAuthToken (default = null) — (optional) Overwrites the access token. Used to pass the request token when requesting an access token.

Returns
SoundcloudDelegate — A SoundcloudDelegate instance you can attach a listener to for the SoundcloudEvent and SoundcloudFault events
getAccessToken()method 
public function getAccessToken(verificationCode:String = null, externalRequestToken:OAuthToken = null):SoundcloudDelegate

Retrieves the access token.

This token will be used for all subsequent API calls. You should store it and reuse it the next time the current user opens your app.

Parameters

verificationCode:String (default = null) — The code that is displayed on the confirmation page after user authorization. This parameter is optional because it won't be generated when you use legacy OAuth 1.0 authentication
 
externalRequestToken:OAuthToken (default = null) — A previously saved request token. You need to use this parameter when you want to call getAccessToken from the callbackURL page

Returns
SoundcloudDelegate — A SoundcloudDelegate instance you can attach a listener to for the SoundcloudEvent and SoundcloudFault events
getRequestToken()method 
public function getRequestToken(callbackURL:String = null):SoundcloudDelegate

Retrieves a request token.

This token must be traded for an access token by calling getAccessToken() after user authentication

Parameters

callbackURL:String (default = null) — (optional) the user will be redirected to this page after authentication. this url will be extended with parameters that you can use on the page: oauth_token: the request token the user authorized or denied oauth_verifier: the verification code (only for OAuth 1.0a)

Returns
SoundcloudDelegate — a SoundcloudDelegate instance you can attach a listener to for the SoundcloudEvent and SoundcloudFault events
sendRequest()method 
public function sendRequest(resource:String, method:String, data:Object = null):SoundcloudDelegate

Make a request to the API.

Parameters

resource:String — The resource locator, e.g. "user/myUserId/tracks"
 
method:String — GET, POST, PUT or DELETE. Note that FlashPlayer only supports GET and POST as of this writing. AIR supports all four methods.
 
data:Object (default = null) — (optional) A generic object containing the request parameters

Returns
SoundcloudDelegate — A SoundcloudDelegate instance you can attach a listener to for the SoundcloudEvent and SoundcloudFault events
Event Detail
accessToken Event
Event Object Type: com.dasflash.soundcloud.as3api.events.SoundcloudAuthEvent
SoundcloudAuthEvent.type property = com.dasflash.soundcloud.as3api.events.SoundcloudAuthEvent.ACCESS_TOKEN

Dispatched when the client receives an access token after getAccessToken has been called.

Wait for this event before calling any non-public resources. If you're building an AIR application you can also use this event to store the access token in the local file system.

accessTokenFault Event  
Event Object Type: com.dasflash.soundcloud.as3api.events.SoundcloudFaultEvent
SoundcloudFaultEvent.type property = com.dasflash.soundcloud.as3api.events.SoundcloudFaultEvent.ACCESS_TOKEN_FAULT

Dispatched when the request of getAccessToken has failed.

The most likely reason is that the verification code was wrong. Other reasons could be network problems, a bad request token or an invalid user. You can check this events message and errorCode properties for details.

requestToken Event  
Event Object Type: com.dasflash.soundcloud.as3api.events.SoundcloudAuthEvent
SoundcloudAuthEvent.type property = com.dasflash.soundcloud.as3api.events.SoundcloudAuthEvent.REQUEST_TOKEN

Dispatched when the client receives a request token after getRequestToken has been called.

Wait for this event before continuing with the next step in the authentication process, authorizeUser.

requestTokenFault Event  
Event Object Type: com.dasflash.soundcloud.as3api.events.SoundcloudFaultEvent
SoundcloudFaultEvent.type property = com.dasflash.soundcloud.as3api.events.SoundcloudFaultEvent.REQUEST_TOKEN_FAULT

Dispatched when the request of getRequestToken has failed.

This event most likely occurs when there are network problems. You can check this events message and errorCode properties for details.

Constant Detail
accessTokenResourceConstant
protected const accessTokenResource:String = oauth/access_token

requestTokenResourceConstant 
protected const requestTokenResource:String = oauth/request_token

Examples
The following code retrieves a list of public tracks:
     var scClient:SoundcloudClient = new SoundcloudClient();
     
     var delegate:SoundcloudDelegate = scClient.sendRequest("tracks");
     
     delegate.addEventListener(SoundcloudEvent.REQUEST_COMPLETE, requestCompleteHandler);
     
     protected function requestCompleteHandler(event:SoundcloudEvent):void
     {
          trace(event.data);
     }