Skip to content

Instantly share code, notes, and snippets.

@nicholas0g
Last active May 14, 2018 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholas0g/80f1ff95c0e55ab06b78b32f0d89f507 to your computer and use it in GitHub Desktop.
Save nicholas0g/80f1ff95c0e55ab06b78b32f0d89f507 to your computer and use it in GitHub Desktop.
Esempio facebook
//necessari moment e reques come moduli!
router.get('/tokenfromfblogin', function (req, res) {
var exp=moment().add(1, 'days').valueOf();
var token = req.headers['fbtoken']; //passo nell'header il toke facecbook dellutente
const options = {
method: 'GET',
uri: `https://graph.facebook.com/v2.11/me?fields=id,name,email`,
qs: {
access_token: token,
}
};
request(options)
.then(fbRes => {
var ok = JSON.parse(fbRes); //la var ok contiene oggetto json co i dati presi dal profilo fb dell'utente!
if (ok['email'] == undefined || ok['name'] == undefined || ok['id'] == undefined) res.json({ result:false, message: 'facebook toke error, missing scope for id, name or email' });
else{
//faccio roba con i dati in ok
}
}).catch(function (err) {
res.json({ result:false, message: 'chiamata api facebook fallita, token non valido'});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment