Using MusicKitJS to Integrate Your Web Application With Apple Music

Photo by Alexander Shatov on Unsplash

Create a MusicKit Identifier

Create a Private Key for Apple Music

Create a JSON Web Token

Embedding MusicKit in Your Frontend

<script src="https://js-cdn.music.apple.com/musickit/v1/musickit.js"></script>
<script>
document.addEventListener('musickitloaded', function() {
// MusicKit global is now defined
MusicKit.configure({
developerToken: 'INSERT TOKEN HERE',
app: {
name: 'INSERT NAME HERE',
build: 'INSERT NUMBER HERE'
}
})
let music = MusicKit.getInstance();
document.getElementById('login-btn').addEventListener('click', () => {
music.authorize().then(function(token) {
// do something with token here
window.location.href += "?music-user-token=" + encodeURIComponent(token);
}).catch (e => {
console.log ('Error:' + e );
});
});
});
</script>

Extra Information/Notes

Computer Science and Business Administration Student @ USC | Backend Developer @ Discotech | Passionate about Software Engineering

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store