Hikaru Shindo
Hikaru Shindo

Reputation: 2913

How to use curl -F in nodejs?

I am trying to build a website that connect with Instagram.

And I want to subscribe Instagram's tag for real time.

curl -F 'client_id=CLIENT-ID' \
 -F 'client_secret=CLIENT-SECRET' \
 -F 'object=tag' \
 -F 'aspect=media' \
 -F 'object_id=nofilter' \
 -F 'callback_url=http://YOUR-CALLBACK/URL' \
 https://api.instagram.com/v1/subscriptions/

I really don't know how to do this in nodejs.

Upvotes: 0

Views: 954

Answers (2)

dzm
dzm

Reputation: 23544

As others have said, request is likely the easiest solution. However, if you have to use curl directly, the following can work natively:

var spawn = require('child_process').spawn;

var command = spawn('curl', []);

command.stderr.on('data', function(data) { });

command.stdout.on('data', function(data) { });

command.stdout.on('close', function() {  });

See spawn command arguments for more information. Alternatively, node-curl is available.

Upvotes: 1

Transcendence
Transcendence

Reputation: 2696

You'll need the request library for the following code. https://github.com/request/request

var request = require('request');

var formData = {
  client_secret: "CLIENT-SECRET",
  object: "tag",
  aspect: "media",
  "object_id": "nofilter",
  "callback_url": "http://YOUR-CALLBACK/URL"
};

request.post({
  url: "https://api.instagram.com/v1/subscriptions/",
  formData: formData
}, function (err, res, body) {
  if (err) {
    console.log(err);
  } else {
    console.log(body);
  }
});

Upvotes: 3

Related Questions