Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

608
Views
Token de acceso de Discord Ouath2 'El tipo de concesión Ninguno no es compatible'

Estoy tratando de hacer un sistema de inicio de sesión con discord para mi sitio web que está hecho con express. Hice una función para obtener un token de acceso para poder usar esa función en la ruta.

Estoy tratando de obtener un token de acceso de: https://discord.com/api/oauth2/token

Aquí está mi código:

 async GetToken(code) { let access_token; const payload = { 'client_id': client_id, 'client_secret': client_secret, 'grant_type': 'authorization_code', 'code': code, 'redirect_uri': redirect_uri, 'scope': scope, }; const config = { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, }; fetch(discord_token_url, { method: 'post', body: payload, headers: config.headers, }).then(response => response.json()).then(json => console.log(json)).catch(err => console.log(err)); return access_token; },

Y aquí está el error que me sale:

 { error: 'unsupported_grant_type', error_description: 'Grant type None is not supported' }

Como puede ver, he dado el tipo de subvención correcto pero recibo este error.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Olvidé actualizar para agregar la solución y vi a mucha gente mirando esto, así que aquí está la solución (gracias a @Kira): Tienes que usar URLSearchParams

 // Modules const fetch = require('node-fetch'); const { url } = require('inspector'); const { URLSearchParams } = require('url'); // Add the parameters const params = new URLSearchParams(); params.append('client_id', client_id); params.append('client_secret', client_secret); params.append('grant_type', 'authorization_code'); params.append('code', code); params.append('redirect_uri', redirect_uri); params.append('scope', scope); // Send the request fetch('https://discord.com/api/oauth2/token', { method: 'post', body: params, headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json' }, }).then(r => r.json()).then(Response => { // Handle it... handle() });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!