I have a Facebook desktop application and am using the Graph API. I am able to get the access token, but after that is done - I don\'t know how to get the user\'s ID.
<Check out this answer, which describes, how to get ID response. First, you need to create method get data:
const https = require('https');
getFbData = (accessToken, apiPath, callback) => {
const options = {
host: 'graph.facebook.com',
port: 443,
path: `${apiPath}access_token=${accessToken}`, // apiPath example: '/me/friends'
method: 'GET'
};
let buffer = ''; // this buffer will be populated with the chunks of the data received from facebook
const request = https.get(options, (result) => {
result.setEncoding('utf8');
result.on('data', (chunk) => {
buffer += chunk;
});
result.on('end', () => {
callback(buffer);
});
});
request.on('error', (e) => {
console.log(`error from facebook.getFbData: ${e.message}`)
});
request.end();
}
Then simply use your method whenever you want, like this:
getFbData(access_token, '/me?fields=id&', (result) => {
console.log(result);
});
The easiest way is
https://graph.facebook.com/me?fields=id&access_token="xxxxx"
then you will get json response which contains only userid.