0
0

More than 5 years have passed since last update.

ExpressでfacebookAPIのパース

Posted at

faceookのapiはものによってはhttps通信じゃないと行けないみたいなのでhttpsをrequireします.
facebookはグループのAPIです.アクセストークンを使います.

routs/index.js
var https = require('https');
var url = 'https://graph.facebook.com/(グループのID)/feed?access_token=(アクセストークン)';
var response = https.get(url, function(res){
    var body = '';
    res.setEncoding('utf8');

    res.on('data', function(chunk){
        body += chunk; //console.log(body);←元データ
    });

    res.on('end', function(res){
        ret = JSON.parse(body);
        response = ret.data;
        //console.log(response);
    });
}).on('error', function(e){
    console.log(e.message); //エラー時
});

exports.index = function(req, res){
    console.log(response);
    res.render('index', { title: 'Express', data: response});
};

これでdataの中身をviewで利用することが出来ました.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0