NodeJS + Express - getting Instagram JSON data from URL

2960 views node.js
-1

I'm trying to display the JSON data form instagram's URL: https://www.instagram.com/apple/?__a=1.

If I put this in browser, it shows the JSON, but I want to be able to get it with express so I can attempt to capture any data I need to with that URL

const express = require("express");
const Instagram = require("node-instagram").default;
const keys = require("./config/keys");
const app = express();
const request = require("request");

app.get("/", (req, res) => {
  const url = "https://www.instagram.com/apple/?__a=1";
  request(url, (err, response, body) => {
    const json = JSON.parse(body);
    console.log(json); 
    res.json(request.json);
  });
});

app.listen(5000);

When I'm trying to deploy this in localhost, I'm getting an error:

SyntaxError: Unexpected end of JSON input

answered question

1 Answer

11

the url https://www.instagram.com/apple/?__a=1 responds wit a 403 (access denied) error. You are not checking for errors in the request (err in your callback).

According to the instagram developer documentation, you need to register your app and authenticate before you can perform the request with Oauth credentials.

posted this

Have an answer?

JD

Please login first before posting an answer.