Created
November 25, 2013 18:08
-
-
Save vgheri/7645741 to your computer and use it in GitHub Desktop.
// Call facebook API to verify the token is valid
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
// 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