开发者

Node.js: How to access FaceBook Ads API

开发者 https://www.devze.com 2023-03-15 13:04 出处:网络
How can I access Facebook Ads API using Node.j开发者_运维知识库s?The same way you access any other API in node, by using http.createClient

How can I access Facebook Ads API using Node.j开发者_运维知识库s?


The same way you access any other API in node, by using http.createClient

This example is based on a proxy, but can be adapted to make any sort of request

Borrowed from from http://www.catonmat.net/http-proxy-in-nodejs/

var http = require('http');

http.createServer(function(request, response) {
  var proxy = http.createClient(80, request.headers['host'])
  var proxy_request = proxy.request(request.method, request.url, request.headers);

  proxy_request.addListener('response', function (proxy_response) {
    proxy_response.addListener('data', function(chunk) {
      response.write(chunk, 'binary');
    });
    proxy_response.addListener('end', function() {
      response.end();
    });
    response.writeHead(proxy_response.statusCode, proxy_response.headers);
  });

  request.addListener('data', function(chunk) {
    proxy_request.write(chunk, 'binary');
  });
  request.addListener('end', function() {
    proxy_request.end();
  });
}).listen(8080);
0

精彩评论

暂无评论...
验证码 换一张
取 消