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

226
Views
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 answers
Answer question

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