stanislavhannes/soundcloud
Composer 安装命令:
composer require stanislavhannes/soundcloud
包简介
PHP SDK for Soundcloud API
README 文档
README
A PHP SDK for the SoundCloud Public API, built on Saloon.
Installation
composer require stanislavhannes/soundcloud
Authentication
SoundCloud supports two OAuth 2.1 flows. Which one you need depends on whether you want to access public data only or a specific user's private data.
| Flow | Access | Me resource works? |
|---|---|---|
| Client Credentials | Public resources only | ❌ No |
| Authorization Code | User's private data | ✅ Yes |
Client Credentials
Use this for accessing public resources (tracks, playlists, public user profiles, search, URL resolution). The SDK automatically fetches an OAuth token and refreshes it when it expires (~1 hour).
Important: SoundCloud requires credentials to be sent as an HTTP Basic Auth header (
Authorization: Basic Base64(client_id:client_secret)), not as form body fields. This SDK handles that automatically.
Important: The
Meresource (/me/*endpoints) returns401 Unauthorizedwith a client credentials token. These endpoints require a user-level token obtained via the Authorization Code flow. If you want to access your own followings, feed, likes etc., use theUsersresource with your numeric user ID instead:// Resolve your profile URL to get your numeric user ID $userId = $client->miscellaneous()->resolveUrl('https://soundcloud.com/your-username')->json('id'); // Then use the public Users resource $followings = $client->users()->userFollowings($userId, 200);
use Stanislavhannes\Soundcloud\Soundcloud; $client = new Soundcloud(); $client->authenticateWithClientCredentials('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET'); // All subsequent calls are automatically authenticated $track = $client->tracks()->getTrack(123456789);
Authorization Code (OAuth 2.1 + PKCE)
Use this when you need to access or act on behalf of a specific user — their private tracks, feed, followings, likes, etc. This requires the user to log in via SoundCloud's connect screen. PKCE is required.
Once you have the user's access token, pass it directly:
use Stanislavhannes\Soundcloud\Soundcloud; use Saloon\Http\Auth\TokenAuthenticator; $client = new Soundcloud(); $client->authenticate(new TokenAuthenticator('USER_ACCESS_TOKEN')); // Me resource now works $profile = $client->me()->userInfo(); $followings = $client->me()->userFollowings(50, null);
See the SoundCloud API guide for how to implement the full redirect + PKCE + token exchange flow.
Manual Token
If you already have an access token from any source:
use Stanislavhannes\Soundcloud\Soundcloud; use Saloon\Http\Auth\TokenAuthenticator; $client = new Soundcloud(); $client->authenticate(new TokenAuthenticator('YOUR_ACCESS_TOKEN'));
Internal Mode
SoundCloud's unofficial api-v2.soundcloud.com endpoint allows broader access using only a client_id. Useful for read-only use cases without user authentication.
use Stanislavhannes\Soundcloud\Soundcloud; $client = new Soundcloud(); $client->enableInternalMode('YOUR_CLIENT_ID'); $track = $client->tracks()->getTrack(123456789);
Available Resources
Tracks
// Get a track $client->tracks()->getTrack($trackId, $secretToken); // Upload a track $client->tracks()->uploadTrack(); // Update a track $client->tracks()->updateTrack($trackId); // Delete a track $client->tracks()->deleteTrack($trackId); // Start a track preview $client->tracks()->trackPreview($trackId, $secretToken); // Get streaming URLs $client->tracks()->trackStreams($trackId, $secretToken); // Get related tracks $client->tracks()->relatedTracks($trackId, $access, $limit, $offset, $linkedPartitioning); // Get comments $client->tracks()->getTrackComments($trackId, $limit, $offset, $linkedPartitioning); // Post a comment $client->tracks()->createComment($trackId); // Get playlists containing this track $client->tracks()->getTrackPlaylists($trackId, $limit, $offset, $linkedPartitioning); // Get users who liked the track $client->tracks()->trackFavoriters($trackId, $limit, $linkedPartitioning); // Get users who reposted the track $client->tracks()->trackReposters($trackId, $limit);
Playlists
// Get a playlist $client->playlists()->getPlaylist($playlistId, $secretToken, $access, $showTracks); // Create a playlist $client->playlists()->createPlaylist(); // Update a playlist $client->playlists()->updatePlaylist($playlistId); // Delete a playlist $client->playlists()->deletePlaylist($playlistId); // Get playlist tracks $client->playlists()->playlistTracks($playlistId, $secretToken, $access, $linkedPartitioning); // Get users who reposted the playlist $client->playlists()->playlistReposters($playlistId, $limit);
Users
// Get a user $client->users()->getUser($userId); // Get user's tracks $client->users()->userTracks($userId, $access, $limit, $linkedPartitioning); // Get user's playlists $client->users()->userPlaylists($userId, $access, $showTracks, $limit, $linkedPartitioning); // Get user's liked tracks $client->users()->userLikedTracks($userId, $access, $limit, $linkedPartitioning); // Get user's liked playlists $client->users()->userLikedPlaylists($userId, $limit, $linkedPartitioning); // Get user's followers $client->users()->userFollowers($userId, $limit); // Get users the user is following $client->users()->userFollowings($userId, $limit); // Get user's web profiles / social links $client->users()->userWebProfiles($userId, $limit);
Me (authenticated user)
Requires Authorization Code token. All
/meendpoints return401 Unauthorizedwhen using a client credentials token. See the Authentication section for details.
// Get your profile $client->me()->userInfo(); // Get your feed $client->me()->userFeed($access, $limit); // Get your track feed $client->me()->userTrackFeed($access, $limit); // Get your tracks $client->me()->userTracks($limit, $linkedPartitioning); // Get your playlists $client->me()->userPlaylists($showTracks, $linkedPartitioning, $limit); // Get your liked tracks $client->me()->userLikedTracks($limit, $access, $linkedPartitioning); // Get your liked playlists $client->me()->userLikedPlaylists($limit, $linkedPartitioning); // Get your followers $client->me()->userFollowers($limit); // Get users you follow $client->me()->userFollowings($limit, $offset); // Get recent tracks from users you follow $client->me()->followingsRecentTracks($access, $limit, $offset); // Follow / unfollow a user $client->me()->followUser($userId); $client->me()->unfollowUser($userId);
Search
// Search tracks $client->search()->searchTracks($q, $ids, $genres, $tags, $bpm, $duration, $createdAt, $access, $limit, $offset, $linkedPartitioning); // Search playlists $client->search()->searchPlaylists($q, $access, $showTracks, $limit, $offset, $linkedPartitioning); // Search users $client->search()->searchUsers($q, $ids, $limit, $offset, $linkedPartitioning);
Likes
$client->likes()->likeTrack($trackId); $client->likes()->unlikeTrack($trackId); $client->likes()->likePlaylist($playlistId); $client->likes()->unlikePlaylist($playlistId);
Reposts
$client->reposts()->repostTrack($trackId); $client->reposts()->repostPlaylist($playlistId); $client->reposts()->removePlaylistRepost($playlistId);
OAuth
// Fetch a token manually using client credentials $response = $client->oauth()->clientCredentials($clientId, $clientSecret); $token = $response->json('access_token'); // Sign out (invalidates the current session token) $client->oauth()->signOut();
Miscellaneous
// Resolve a soundcloud.com URL to its API resource URL $client->miscellaneous()->resolveUrl('https://soundcloud.com/artist/track-name');
License
This package is open-sourced software licensed under the MIT license.
stanislavhannes/soundcloud 适用场景与选型建议
stanislavhannes/soundcloud 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 stanislavhannes/soundcloud 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stanislavhannes/soundcloud 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-04