프로젝트/Whatever Song

spotify API postman으로 사용해보기

yeonahn 2025. 3. 16. 02:49

원래 사용하던 블로그 - https://yeonnan.hashnode.dev/spotify-api-postman

 

 

 

 

웹 API 시작하기

  1. Create an app, if you haven't done so.
  2. Request an access token.
  3. Use the access token to request the artist data.

1. CREATE AN APP 해주기

Redirect Url에 뭘 적어야 하는지 고민을 많이 했는데, 
리다이렉트 URI는 Spotify API 인증 프로세스 후에 사용자가 리다이렉트될 URL을 지정하면 된다.

개발 환경에서 테스트하는 경우, 로컬 버서의 url을 사용하면 되고, 나중에 배포할 때 해당 url로 업데이트 하면 된다. http://127.0.0.1:8000/api/playlist/

2. 액세스 토큰 요청

  • Send a POST request to the token endpoint URI.
  • Add the Content-Type header set to the application/x-www-form-urlencoded value.
  • Add a HTTP body containing the Client ID and Client Secret, along with the grant_type parameter set to client_credentials
curl -X POST "https://accounts.spotify.com/api/token" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "grant_type=client_credentials&client_id=your-client-id&client_secret=your-client-secret"


postman으로 돌아가는지 확인하기

curl -X POST "https://accounts.spotify.com/api/token"

→ post 형식이고 주소는 https://accounts.spotify.com/api/token

H "Content-Type: application/x-www-form-urlencoded"

→ headers에 content-type으로 application/x-www-form-urlencoded 적어주기

-d "grant_type=client_credentials&client_id=your-client-id&client_secret=your-client-secret"

→ grant_type=client_credentials

→ client_id=your-client-id

→ client_secret=your-client-secret

이렇게 작성해주면 아래와 같은 1시간 동안 유효한 엑세스 토큰을 반환한다.


아티스트 데이터 요청하기

  1. Search the artist
  2. Click on the three dots icon from the artist profile
  3. Select Share > Copy link to artist. The Spotify ID is the value that comes right after the open.spotify.com/artist URI.

Our API call must include the access token we have just generated using the Authorization header as follows:

별다른 요청이 없기때문에 GET 방식으로 첫줄 주소 작성

BearerToken 자리에 발급받아서 나온 토큰 작성해주면 목록이 나온다.