Skip to content

Instantly share code, notes, and snippets.

@vgheri
Created November 25, 2013 18:08
Show Gist options
  • Save vgheri/7645741 to your computer and use it in GitHub Desktop.
Save vgheri/7645741 to your computer and use it in GitHub Desktop.
// Call facebook API to verify the token is valid
// Call facebook API to verify the token is valid
// https://graph.facebook.com/me?access_token=$token
function verifyFacebookUserAccessToken(token) {
var deferred = Q.defer();
var path = 'https://graph.facebook.com/me?access_token=' + token;
request(path, function (error, response, body) {
var data = JSON.parse(body);
if (!error && response && response.statusCode && response.statusCode == 200) {
var user = {
facebookUserId: data.id,
username: data.username,
firstName: data.first_name,
lastName: data.last_name,
email: data.email
};
deferred.resolve(user);
}
else {
console.log(data.error);
//console.log(response);
deferred.reject({code: response.statusCode, message: data.error.message});
}
});
return deferred.promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment