# 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/`](http://127.0.0.1:8000/api/playlist/)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716205382576/745bdba6-2219-4685-8fba-eb0ee0b345c4.png align="center")

## 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
    

```plaintext
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"
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716205417554/0062def3-845c-4f53-87f1-14a8282d67d4.png align="center")

---

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

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

→ post 형식이고 주소는 [`https://accounts.spotify.com/api/token`](https://accounts.spotify.com/api/token)

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

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716205448236/48a2a997-099c-4fd2-b49e-acc964739640.png align="center")

#### \-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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716205464812/02c8626f-df97-4661-b218-a779f572b90f.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716205473450/7274ae27-fc66-42b7-91c8-04296170a027.png align="center")

---

# 아티스트 데이터 요청하기

1. Search the artist
    
2. Click on the three dots icon from the artist profile
    
3. Select *Share &gt; Copy link to artist*. The Spotify ID is the value that comes right after the [`open.spotify.com/artist`](http://open.spotify.com/artist) URI.
    

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716205493412/f4b81ba0-833f-4284-a06f-051b215c3213.png align="center")

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

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716205502450/05d64dbc-eb56-4a7c-97d1-0721e0d303df.png align="center")
