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

229
Vistas
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 Respuestas
Responde la pregunta

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 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