Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Defining the required NodeJS dependencies
- var graph = require('fbgraph');
- var fs = require('fs');
- var config = require('config-ini');
- // Defining variables needed globally
- var oldMessage = "";
- var fileLocation = "";
- // Extanding static access token
- function extendAccessToken(){
- graph.extendAccessToken ({
- "client_id": config.app.client_id,
- "client_secret": config.app.client_secret
- }, function(err, facebookRes) {
- if (err) {
- console.log(err);
- }
- });
- }
- // Main function that outputs the update to the terminal and writes it to a file
- function getFeed(){
- graph.get("me/home?limit=1", function(err, res) {
- if(err) {
- console.log(err);
- }
- if ( typeof JSON.stringify(res).split('"')[5] !== 'undefined') {
- if ( JSON.stringify(res).split('"')[5] != oldMessage ) {
- console.log(res);
- fs.appendFile(fileLocation, "\r\n"+JSON.stringify(res), function (err) {
- if (err) {
- console.log(err);
- }
- });
- console.log("******************************************");
- oldMessage = JSON.stringify(res).split('"')[5];;
- }
- }
- });
- }
- // What should be executed when this node is run
- config.load(['config.ini'], function(err) {
- if (err) {
- throw new Error(err); //File not found
- }
- graph.setAccessToken(config.app.accessToken);
- fileLocation = config.file.location;
- setInterval(extendAccessToken, 10000);
- setInterval(getFeed, 3000);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement