구글링을 통해 Spotify API 플레이어를 적용하는 방법을 검색했고 좋은 예시들이 많아보여서 천천히 따라해 보았다.
<!DOCTYPE html>
<html>
<head>
<title>Spotify Web Playback SDK Quick Start</title>
</head>
<body>
<h1>Spotify Web Playback SDK Quick Start</h1>
<button id="togglePlay">Toggle Play</button>
<script src="https://sdk.scdn.co/spotify-player.js"></script>
<script>
window.onSpotifyWebPlaybackSDKReady = () => {
const token = '[My access token]';
const player = new Spotify.Player({
name: 'Web Playback SDK Quick Start Player',
getOAuthToken: cb => { cb(token); },
volume: 0.5
});
// Ready
player.addListener('ready', ({ device_id }) => {
console.log('Ready with Device ID', device_id);
});
// Not Ready
player.addListener('not_ready', ({ device_id }) => {
console.log('Device ID has gone offline', device_id);
});
player.addListener('initialization_error', ({ message }) => {
console.error(message);
});
player.addListener('authentication_error', ({ message }) => {
console.error(message);
});
player.addListener('account_error', ({ message }) => {
console.error(message);
});
document.getElementById('togglePlay').onclick = function() {
player.togglePlay();
};
player.connect();
}
</script>
</body>
</html>
콘솔에서 Device ID를 나오게 하는것 까지는 성공
안된다. 애초에 재생 플레이어가 나오지도 않는다. Maven 환경에서의 문제일까 생각해보고 구글링을 통해 의존성도 추가해주고 공식 홈페이지에 찾아가 번역을 하여 처음부터 끝까지 따라해봐도 안된다.
OAuth 2.0 문제였다. AI에게 코드를 보여주고 질문을 계속 해본 결과 Spotify 플레이어를 불러오기 위해서는 인증이 필수적이라는 답변을 얻었다.
내가 구글링 했던 API의 정보들은 Spotify의 재생 데이터를 불러올 뿐이었고 더 찾아본 결과 플레이어를 연동하는 방법은 로그인을 해야 한다고 알려주었는데 OAuth 2.0 인증에 대해 어디에서도 알려주지 않았었다.
주요 기능(아이템 추천 기능) 완성하기
이번주 내로
중간 보고 발표 준비.