SoundCloud
is a Swift Package that implements the SoundCloud Public API Specification (v1.0.0) .
It handles the logic for authenticating with a SoundCloud account using the OAuth 2.0 standard, and provides an API for streaming audio and accessing track, artist, and playlist data from SoundCloud.
Add the following line to your project's dependencies in the Package.swift file:
.package(url: "https://github.com/superturboryan/SoundCloud-api"),
and include "SoundCloud" as a dependency for your executable target:
.target(name: "Your App", dependencies: ["SoundCloud", ...]),
Define a custom URL scheme for your app, you will need to provide a redirect URI using the scheme so that the OAuth web page knows how to open your app when it receives the tokens callback.
The redirect URI used when creating the SoundCloud
instance must also be paired with the client ID and client secret for your SoundCloud registered app.
To login using a SoundCloud account:
import SoundCloud
let config = SoundCloudConfig(apiURL: ...)
@StateObject var sc = SoundCloud(config)
...
do {
try await sc.login()
} catch {
// Handle login error
}
To get the liked tracks for the current user:
let likedTracks = try await sc.getMyLikedTracks()
SoundCloud requires apps to be registered in order to access their public API. See terms of use