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

433
Vistas
Instagram API Access Token Request Javascript

Hello I have tried to use the instagram api to get a connection token. I first tested it on postman and this is what I did: I used this link to make a request post to the instagram api:

https://api.instagram.com/oauth/access_token?client_id=clientid&client_secret=clientsecret&grant_type=authorization_code&redirect_uri=https://mysite/&code=thecode

The api gives me an error: Missing required field client_id

But when I set the content type to x-www-form-urlencoded everything works fine on postman.

So I tried to do the same thing in javascript with the node module request. I tried to do the same thing as on postman with the module but it does not work... Here is my code:

request(`https://api.instagram.com/oauth/access_token?client_id=clientid&client_secret=clientsecret&grant_type=authorization_code&redirect_uri=https://mysite/&code=` + code, {
        method: 'POST',
        headers: {"Content-Type": "x-www-form-urlencoded"}
    }, (error, response, body) => {
        console.log('body:', body)
    })
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As per MDN, the content type should be application/x-www-form-urlencoded https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST

Update: You should read the node doc : https://nodejs.dev/learn/making-http-requests-with-nodejs

Get method:

const https = require('https');

const options = {
  hostname: 'api.instagram.com',
  path: '/oauth/access_token?client_id=clientid&client_secret=clientsecret&grant_type=authorization_code&redirect_uri=https://mysite/&code=thecode',
  method: 'GET',
  headers: {
        "Content-Type": "application/x-www-form-urlencoded", 
        "Accept": "Accept-Encoding"
  }
};

const req = https.request(options, (res) => {
  // ...
});

Post method:

var headers = {
  "Content-Type": "application/x-www-form-urlencoded", 
    "Accept": "Accept-Encoding"
};

var options = {
  url: 'https://api.instagram.com/oauth/access_token',
  method: 'POST',
  headers: headers
};

var form = {
  grant_type:'urn:ietf:params:oauth:grant-type:jwt-bearer',
  client_id: 'id',
  client_secret: 'secret'
  redirect_uri : 'https://mysite/&code=thecode'
};

var request = https.request(options, function(response) {
  // do stuff
});

request.write(querystring.stringify(form));
request.end();
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