Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

434
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda