Last active
May 14, 2018 13:51
-
-
Save nicholas0g/80f1ff95c0e55ab06b78b32f0d89f507 to your computer and use it in GitHub Desktop.
Esempio facebook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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