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

235
Visualizações
Instagram api working fine on localhost but sending error on server (https://www.instagram.com/${name}/?__a=1)

I am using trying to get some profile information of a user.it is working on local host but not on server.I am not logged in instgram account on local/my pc.It looks like on server it is trying to log in first.

  let username = req.query.username;
  if (!username) {
    throw "Please enter a username";
  }      
  let name = username.toLowerCase();

  // console.log("name", name);
  var instagram_url = `https://www.instagram.com/${name}/?__a=1`;
  // console.log("url", instagram_url);
  // let response = await axios.get(
  // `https://api.lamadava.com/v1/user/by/username?username=hamimkivines&access_key=${access_key}
  // );
  let response = await fetch(instagram_url);
  console.log("response -", response); 
 
  let profile = await response.json();
  // console.log("profile", profile);
  return res.status(200).send(profile); 

  **Local response -**
  [Symbol(Response internals)]: {
    url: 'https://www.instagram.com/hamimkivines/?__a=1',
    status: 200,
    statusText: 'OK',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }


**Server Response**
0|dev  |   [Symbol(Response internals)]: {
0|dev  |     url: 'https://www.instagram.com/accounts/login/',
0|dev  |     status: 200,
0|dev  |     statusText: 'OK',
0|dev  |     headers: Headers { [Symbol(map)]: [Object: null prototype] },
0|dev  |     counter: 1
0|dev  |   }
0|dev  | 
0|dev  | error FetchError: invalid json response body at https://www.instagram.com/accounts/login/ reason: Unexpected token < in JSON at position 0
0|dev  |     at /var/www/html/everlensv2node/node_modules/node-fetch/lib/index.js:273:32
0|dev  |     at processTicksAndRejections (internal/process/task_queues.js:95:5)
0|dev  |     at async getInstagramProfile (/var/www/html/everlensv2node/modules/user/user.controller.js:188:21) {
0|dev  |   type: 'invalid-json'
0|dev  | }
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This is caused by the API endpoint is returning the HTML tags enclosing the JSON data. Instead of using response.json() try

let profile = response.text()
let parsed_json = JSON.parse(profile)

If this doesnt work, you will have to manually strip the enclosing tags of the XML being returned.

about 4 years ago · Santiago Trujillo 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