Created
June 11, 2016 16:35
-
-
Save clarencetw/06d670bd1e5f423a4bd79a02fdeebe39 to your computer and use it in GitHub Desktop.
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
var FB = require('fb'); | |
var readline = require('readline'); | |
FB.options({ | |
appId: '', | |
appSecret: '', | |
redirectUri: '' | |
}); | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
function getAccessToken (callback) { | |
console.log('Visit the url: ', FB.getLoginUrl({ scope: 'user_about_me' })); | |
rl.question('Enter the code here:', function (code) { | |
FB.api('oauth/access_token', { | |
client_id: FB.options('appId'), | |
client_secret: FB.options('appSecret'), | |
redirect_uri: FB.options('redirectUri'), | |
code: code | |
}, function (res) { | |
if(!res || res.error) { | |
console.log(!res ? 'error occurred' : res.error); | |
return; | |
} | |
var accessToken = res.access_token; | |
var expires = res.expires ? res.expires : 0; | |
callback(accessToken); | |
}); | |
}); | |
} | |
getAccessToken(function (token) { | |
FB.setAccessToken(token); | |
FB.api('me', { fields: ['id', 'name'] }, function (res) { | |
if(!res || res.error) { | |
console.log(!res ? 'error occurred' : res.error); | |
return; | |
} | |
console.log(res.id); | |
console.log(res.name); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment