Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
Respuesta de error del servidor Spotify API OAUTH2 al solicitar token

Spotify Oauth2 Docs - Flujo de credenciales del cliente

Hice una pregunta similar y pude ejecutar el código en el script de aplicaciones de Google (javascript). Estoy usando Flujo de credenciales de cliente. Sin embargo, traté de recrear este código en Nodejs. Al ejecutar este código, recibo un error del servidor.

 error: "server_error"

Este es el código del problema en Nodejs

 const defaultConfig = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', // this encodes the app_id and api_key into a base64 string like the documentation states 'Authorization': `Basic ${btoa(spotify.API_ID + ':' + spotify.API_KEY)}` }, body: JSON.stringify({ 'grant_type': 'client_credentials', }) }; // this function is wrapped in a list titled, "apiSettings" with other functions. I just included the authorization function here: const apiSettings = { getSpotifyAuthorizeToken: async () => { const endpoint = "https://accounts.spotify.com/api/token"; return await (await fetch(endpoint, defaultConfig)).json(); }, };

Obtuve este código similar para trabajar en el script de aplicaciones de Google sin problemas.

¿Podría el error del servidor ser el resultado de que ejecuté Nodejs en un "localhost: xxxx"? La documentación establece que "el flujo de credenciales de cliente se usa en la autenticación de servidor a servidor".

si este no es el caso, ¿podría proporcionar un trabajo

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Respuesta de error del servidor Spotify API OAUTH2 al solicitar token

De su pregunta anterior , me gustaría proponer los siguientes scripts de muestra.

Ejemplo de guión 1:

Si desea convertir el script de esta respuesta a Node.js y node-fetch, ¿qué tal el siguiente script?

 const spotify = { API_ID: "API_ID", API_KEY: "API_KEY" }; // Please set your client ID and client secret. const buf = Buffer.from(spotify.API_ID + ":" + spotify.API_KEY); const para = new URLSearchParams(); para.append("grant_type", "client_credentials"); const defaultConfig = { method: "POST", headers: { Authorization: `Basic ${buf.toString("base64")}` }, body: para, }; const apiSettings = { getSpotifyAuthorizeToken: async () => { const endpoint = "https://accounts.spotify.com/api/token"; return await (await fetch(endpoint, defaultConfig)).json(); }, };

Guión de muestra 2:

Si desea convertir el script de esta respuesta a Node.js y node-fetch, ¿qué tal el siguiente script?

 const spotify = { API_ID: "API_ID", API_KEY: "API_KEY" }; // Please set your client ID and client secret. const para = new URLSearchParams(); para.append("grant_type", "client_credentials"); para.append("client_id", spotify.API_ID); para.append("client_secret", spotify.API_KEY); const defaultConfig = { method: "POST", body: para, }; const apiSettings = { getSpotifyAuthorizeToken: async () => { const endpoint = "https://accounts.spotify.com/api/token"; return await (await fetch(endpoint, defaultConfig)).json(); }, };

Referencia:

  • búsqueda de nodo
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda