Instagram API not working via Nodejs

0 votes

Here is my http POST code, running on localhost:

if(headers['Content-Type'] == undefined)
        headers['Content-Type'] = 'application/x-www-form-urlencoded';

    var post_options = {
          host: host,
          path: path,
          port: port,
          method: 'POST',
          headers: headers
    };

    if(headers['Content-Type'] == "application/json"){
        post_options["json"] = true;
        var post_data = JSON.stringify(body);
    }else
        var post_data = querystring.stringify(body);

     var post_req = http.request(post_options, function(res) {

          var body = '';

          console.log("INSIDE CALLBACK HTTP POST");

          res.setEncoding('utf8');

          res.on('data', function (chunk) {
              body += chunk;
              console.log('Response: ' + chunk);
          });

          res.on('end', function () {
            var post = querystring.parse(body);
            console.log("FINAL BODY:",post);
          });

          //console.log("RESPONSE in http POST:",res);

      });

      // post the data
      console.log("WRITING HTTP POST DATA");
      var sent_handler = post_req.write(post_data);

      console.log("POST_REQ:",post_req);
      console.log("sent_handler:",sent_handler);

      post_req.end();

Here is the information I send to instagram exactly:

  • host = "api.instagram.com"
  • path = "/oauth/access_token"
  • body as follows:

    body["client_id"] = CLIENT_ID;

    body["client_secret"] = CLIENT_SECRET;

    body["grant_type"] = "authorization_code";

    body["redirect_uri"] = AUTHORIZATION_REDIRECT_URI;

    body["code"] = login_code;

    body["scope"] = "public_content";

  • headers = {} (empty, assumes headers['Content-Type'] == undefined as true)

  • Important: sent_handler returns false

  • The console.log for "FINAL BODY" (variable post) returns "{}"

To note: communications using curl with the api instagram works. So I really believe the problem is in some part of this code in nodejs.

Does anyone have any idea? Please ask if there is need for more information

Aug 19, 2022 in Node-js by Neha
• 9,020 points
641 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Node-js

0 votes
1 answer

Nodejs Instagram videos downloader not working

Firstly, Initialize a package.json file with default values. npm ...READ MORE

answered Jun 9, 2022 in Node-js by Neha
• 9,020 points
1,322 views
0 votes
1 answer

Nodejs: question of type input with npm inquirer not working

The right code should be: const outPath = ...READ MORE

answered Jun 7, 2022 in Node-js by Neha
• 9,020 points
1,883 views
0 votes
1 answer

NodeJS express get request is not working on mobile

For your API call, try to add ...READ MORE

answered Jun 7, 2022 in Node-js by Neha
• 9,020 points
1,943 views
0 votes
1 answer

NodeJS express get request is not working on mobile

For your API call, try to add ...READ MORE

answered Jun 9, 2022 in Node-js by Neha
• 9,020 points
533 views
0 votes
0 answers

Mongodb updateMany() not working in nodejs

I have a collection called imported_products with ...READ MORE

Jun 27, 2022 in Node-js by Vaani
• 7,070 points
1,133 views
0 votes
0 answers

npm command not working after installing nodejs in windows10?

i have installed nodejs from nodejs website. ...READ MORE

Aug 11, 2022 in Node-js by Neha
• 9,020 points
1,540 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,922 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP