0

I've read facebook documentation and trying to create a function that when prompted gets the username and profile pic ,et al of the user talking to the bot this is my function

const express = require('express')
const bodyParser = require('body-parser')
const request = require('request') 
const app = express()
/% other code here %/
 function sendNameMessage(sender){
 http.get( "https://graph.facebook.com/v2.6/" +sender +"?fields=first_name,last_name,profile_pic,locale,timezone,gender&access_token="+token
 ,function(response){response.setEncoding('utf8')  
response.on('data', console.log)  
response.on('error', console.error)  })

}

simple to say I have been having issues getting it to work, any help or examples I could use?

James Hennessy
  • 397
  • 6
  • 14

1 Answers1

0

Here is an example code that i've used:

        request({
        url: 'https://graph.facebook.com/v2.6/' + user.id  +  '?access_token='+ FB_PAGE_ACCESS_TOKEN,
        method: 'GET'
        },
    function (error, response, body) {
        if (!error && response.statusCode == 200) {
            // Print out the response body
            console.log('success',body);

        } else { 
            console.log('error',body);
        }
    });

Don't forget to define the user.id and fb token variables.

let me know if you have any more questions.

Amit be
  • 469
  • 3
  • 13