<jupyter_start><jupyter_text>API CONECTIONA continuación trabajaremso con las API de spotify.https://developer.spotify.com/documentation/general/guides/authorization-guide/https://www.base64encode.org/<jupyter_code>pip install pybase64
from bs4 import BeautifulSoup
import base64
import requests
url_api = "https://api.spotify.com"
response = requests.get(url_api)
response
users_playlist_ep ="/v1/me/playlists"
artists_ep = "/v1/artists"
resp = requests.get(url_api+users_playlist_ep)
resp<jupyter_output><empty_output><jupyter_text>Retorna error debido a que  no tengo autorización  mediante el token para poder acceder a esto. Para hacer el request puid eun encabezado para obtener datos, le podemos poner el token<jupyter_code>token_url = "https://accounts.spotify.com/api/token"
# Parametros para el requests

params = {'grant_type':'client_credentials'}
client_id ="f0be6de3bacf403481b8ab2fa0df9f07"
client_credentials ="<PASSWORD>"


client_str ='{client_id}:{client_credentials}'.format(client_id=client_id, client_credentials=client_credentials)
client_encode = base64.b64encode(client_str.encode("utf-8")) #Doficico Bytes
client_encode = str(client_encode, "utf-8") #codificando string
# Requerimos parar el client y el id en codigo base64
token_url = 'https://accounts.spotify.com/api/token'
params = {'grant_type': 'client_credentials'}
headers= {'Authorization' : 'Basic {client_encode}'.format(client_encode=client_encode)}
headers
r = requests.post(token_url, data=params, headers= headers)
r
r.json()
#Los tokens tienen un tiempo de vida útil
token = r.json()['access_token']
# Hacemos el request con el token.
header = {'Authorization': 'Bearer {}'.format(token)}
resp = requests.get(url_api+artists_ep, headers= header)
resp<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup