Archive for the ‘Soundcloud API’ Category

Connect to Soundcloud API

1. Load Soundcloud Library

 $this->load->library("Services_Soundcloud",$config);

2.We have to specify  Client ID  Secret and Redirect URL sc_connect() method

public function sc_connect()
 {
$config = array(
 'clientId'=>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
 'clientSecret'=>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
 'redirecturi'=>"http://127.0.0.1/project/index.php/controller/method"
 );
 $this->load->library("Services_Soundcloud",$config);
$soundcloud = new Services_Soundcloud($config);
$authorizeUrl = $soundcloud->getAuthorizeUrl();
if($authorizeUrl)
 {
 redirect($authorizeUrl);
 }
}

CallBack to Soundcloud API

public function callback()
 {

 $config = array(
 'clientId'=>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
 'clientSecret'=>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
 'redirecturi'=>"http://127.0.0.1/project/index.php/controller/method"
 );

 $this->load->library("Services_Soundcloud",$config);

 $soundcloud = new Services_Soundcloud($config);

 try {
 $accessToken = $soundcloud->accessToken($_GET['code']);
 print_r($accessToken);
 $this->session->set_userdata("access_token",$accessToken);

 } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
 exit($e->getMessage());
 }
 try {
 $me = json_decode($soundcloud->get('me'), true);
 } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
 exit($e->getMessage());
 }

 echo "

";

 print_r($me);
 }
Advertisements

Soundcloud API Library

Download Link : Soundcloud API

Soundcloud Library : Codeigniter  Folder Structure

application/libraries/Soundcloud/Exception.php

application/libraries/Soundcloud/Version.php

application/libraries/Services_soundcloud.php

Creating App

http://soundcloud.com/you/apps

Step 1  : Register Your App

Reg

Step 2 : Form for App Details

Reg2

App Name

URL

Redirect URL (if your are developing Application in localhost use IP Address don’t use localhost)

Save Client ID and Secret

Step 3 : App Created

App