PHPackages                             njasm/soundcloud - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. njasm/soundcloud

ActiveLibrary[API Development](/categories/api)

njasm/soundcloud
================

Soundcloud API Wrapper written in PHP with OAuth 2.0 support

2.2.6(8y ago)100161.8k—4.7%23[2 PRs](https://github.com/njasm/soundcloud/pulls)2MITPHPPHP &gt;=5.6.0CI failing

Since May 13Pushed 1y ago7 watchersCompare

[ Source](https://github.com/njasm/soundcloud)[ Packagist](https://packagist.org/packages/njasm/soundcloud)[ Docs](http://github.com/njasm/soundcloud)[ RSS](/packages/njasm-soundcloud/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (18)Used By (2)

[![Build Status](https://github.com/njasm/soundcloud/actions/workflows/CI.yaml/badge.svg?branch=master)](https://github.com/njasm/soundcloud) [![Code Coverage](https://camo.githubusercontent.com/1ef0e931791a1c6772c031577736ad12ea715a3985980da234ff20ecf5b18613/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e6a61736d2f736f756e64636c6f75642f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/njasm/soundcloud/?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/175502e046a1f0bd92abf09b1b2275bc45d88f892d4f8f3807e1223d204a3d85/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e6a61736d2f736f756e64636c6f75642f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/njasm/soundcloud/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/e5d63c5b7465256f9121d9c261a09fa8798d90189a634a334c61ed5f2bed05a4/68747470733a2f2f706f7365722e707567782e6f72672f6e6a61736d2f736f756e64636c6f75642f762f737461626c652e706e67)](https://packagist.org/packages/njasm/soundcloud) [![Total Downloads](https://camo.githubusercontent.com/05b8a363cf6be196b020a775ff9ff35144dba12dac303585b5c65d052d296c41/68747470733a2f2f706f7365722e707567782e6f72672f6e6a61736d2f736f756e64636c6f75642f646f776e6c6f6164732e706e67)](https://packagist.org/packages/njasm/soundcloud) [![License](https://camo.githubusercontent.com/fbfa17c7d9a34cae6a647473fe5f963e92ddbf1143fc036c55e338116ad31e7d/68747470733a2f2f706f7365722e707567782e6f72672f6e6a61736d2f736f756e64636c6f75642f6c6963656e73652e706e67)](https://packagist.org/packages/njasm/soundcloud)

Soundcloud.com API Wrapper in PHP
---------------------------------

[](#soundcloudcom-api-wrapper-in-php)

#### Implemented features

[](#implemented-features)

- User Authorization/Authentication
- User Credentials Flow Authentication
- Access to all GET, PUT, POST and DELETE Resources
- Media File Download/Upload

### Requirements

[](#requirements)

PHP 5.6 or higher.

#### Installation

[](#installation)

Recommended installation is through composer. Include `njasm\soundcloud` in your project, by adding it to your `composer.json` file.

```
{
    "require": {
        "njasm/soundcloud": "dev-master"
    }
}
```

If you don't use `composer` to manage your project dependencies, this library provides your with an [autoload.php](https://github.com/njasm/soundcloud/blob/master/src/Soundcloud/autoload.php)You just need to include [autoload.php](https://github.com/njasm/soundcloud/blob/master/src/Soundcloud/autoload.php) in your project to start using the library as you would if installed through `composer`.

##### Usage

[](#usage)

Include `Njasm\Soundcloud\` namespace in the script where you intend to use `SoundcloudFacade` or `Soundcloud` class.

```
use Njasm\Soundcloud\SoundcloudFacade;
// or soundcloud if you don't need a facade for specific tasks
use Njasm\Soundcloud\Soundcloud;
```

`SoundcloudFacade.php` provides you with boilerplate code to get authorization url, change a code for a token, etc etc..

##### Examples

[](#examples)

###### Get Authorization Url.

[](#get-authorization-url)

```
$facade = new SoundcloudFacade($clientID, $clientSecret, $callbackUri);
$url = $facade->getAuthUrl();

// or inject your specific request params
$url = $facade->getAuthUrl(
    [
        'response_type' => 'code',
        'scope' => '*',
        'state' => 'my_app_state_code'
    ]
);
```

###### Authentication

[](#authentication)

```
$facade = new SoundcloudFacade($clientID, $clientSecret, $callbackUri);
// this is your callbackUri script that will receive the $_GET['code']
$code = $_GET['code'];
$facade->codeForToken($code);
```

###### Authentication with user credentials flow.

[](#authentication-with-user-credentials-flow)

If an access token is returned from soundcloud, it will be automatically set for future requests. The Response object will always be returned to the client.

```
$facade = new SoundcloudFacade($clientID, $clientSecret);
$facade->userCredentials($username, $password); // on success, access_token is set by default for next requests.
$response = $facade->get('/me')->request();
// raw/string body response
echo $response->bodyRaw();
// as object
echo $response->bodyObject()->id;
// as array
$array = $response->bodyArray();
```

###### Accept response as json or xml

[](#accept-response-as-json-or-xml)

Note: Soundcloud.com stopped sending responses in xml format, the methods are kept in the 2.x.x versions, but calling them will have no effect on the request, all requests will have an accept header of application/json.

```
...
$response  = $facade->get('/tracks')->asJson()->request();
// or
$response = $facade->get('/tracks')->asXml()->request();
```

###### Add params to resource.

[](#add-params-to-resource)

```
// argument array style
$facade->get('/resolve', ['url' => 'http://www.soundcloud.com/hybrid-species']);

// chaining-methods
$response = $facade
    ->get('/resolve')
    ->setParams(['url' => 'http://www.soundcloud.com/hybrid-species']);

// or not
$facade->get('/resolve');
$facade->setParams(['url' => 'http://www.soundcloud.com/hybrid-species']);
```

###### Send request

[](#send-request)

To allow different ways to set the Resource parameters that you are accessing - by submitting an array or setParams() method injection. The request will only be sent to soundcloud, when you invoke the request() method. Take in considerations that specific operations like userCredentials(), download(), etc. will invoke request() automatically.

```
$soundcloud = new Soundcloud($clientID, $clientSecret);
$soundcloud->get('/resolve', ['url' => 'http://www.soundcloud.com/hybrid-species']);
// only this invocation will send the request
$response = $soundcloud->request();
```

###### Get the raw response Body

[](#get-the-raw-response-body)

```
...
$theBodyString = $facade->request()->bodyRaw();
```

###### Create a Playlist / Set and update with tracks

[](#create-a-playlist--set-and-update-with-tracks)

```
// after having the access token
// build the playlist data array
$playlistData = ['playlist' => ['title' => 'Great Playlist!', 'sharing' => 'public']];
$response = $soundcloud->post('/playlists', $playlistData)->request();

// now add tracks, get playlist id from response
// build tracks array
$tracks = [
    'playlist' => [
        'tracks' => [
            ['id' => 29720509], // track id
            ['id' => 26057359]  // other track id
        ]
    ]
];

// put tracks into playlist
$response = $soundcloud->put('/playlists/' . $response->bodyObject()->id, $tracks)->request();
```

###### Get CURL last response object

[](#get-curl-last-response-object)

```
// if you want the CURL response object from last CURL request.
$response = $facade->getCurlResponse();
```

###### File Download

[](#file-download)

```
// this will redirect user, sending a header Location to the track.
$response = $facade->download($trackID);
// redirect user to download URL suplied by soundcloud.
header('Loacation: ' . $response->getHeader('Location'));

// CAUTION: this will get the track into an in-memory variable in your server.
$response = $facade->download($trackID, true);
// save it to a file.
file_put_contents("great_track.mp3", $response->bodyRaw());
```

###### File Upload

[](#file-upload)

```
$trackPath = '/home/njasm/great.mp3';
$trackData = [
    'title' => 'Cool track title',
    'downloadable' => true,
    'artwork_data' => new \CURLFile('artwork.jpg'),
    // .... more metadata maybe?
];

$response = $facade->upload($trackPath, $trackData);

// or old-school trackdata array declaration also work, example.
$trackData = [
    'track[title]' => 'Cool track title',
    'track[downloadable]' => true,
    'track[artwork_data]' => new \CURLFile('artwork.jpg'),
    // .... more metadata maybe?
];

$response = $facade->upload($trackPath, $trackData);
```

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 93.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~101 days

Recently: every ~231 days

Total

14

Last Release

3063d ago

Major Versions

1.1.0 → 2.0.02014-08-04

2.2.2 → 3.0.x-dev2015-06-17

PHP version history (4 changes)1.0.0PHP &gt;=5.3.0

1.1.0PHP &gt;=5.3.3

3.0.x-devPHP &gt;=5.4.0

2.2.6PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d98cf35ac26b9bb2fb6b82509db1a1dced7001af51feee3f0b845b09fcd92181?d=identicon)[njasm](/maintainers/njasm)

---

Top Contributors

[![njasm](https://avatars.githubusercontent.com/u/1623137?v=4)](https://github.com/njasm "njasm (58 commits)")[![Xartrick](https://avatars.githubusercontent.com/u/1482818?v=4)](https://github.com/Xartrick "Xartrick (2 commits)")[![k1ng440](https://avatars.githubusercontent.com/u/3443226?v=4)](https://github.com/k1ng440 "k1ng440 (1 commits)")[![pulkitjalan](https://avatars.githubusercontent.com/u/4124930?v=4)](https://github.com/pulkitjalan "pulkitjalan (1 commits)")

---

Tags

apilibraryphp-libraryrestfulsoundcloudapiwebservicewebservicessoundcloud

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/njasm-soundcloud/health.svg)

```
[![Health](https://phpackages.com/badges/njasm-soundcloud/health.svg)](https://phpackages.com/packages/njasm-soundcloud)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
