2. Soundcloud API : Connection and Call Back

Posted: 26/12/2013 in Soundcloud API
Tags: , , ,

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s