简体   繁体   中英

how can I do facebook login using FB.api

 var FB = require('fb'), fb = new FB.Facebook(options); var options = FB.options(); var {Facebook, FacebookApiException} = require('fb'), fb = new Facebook(options); FB.api('me/feed', 'post', { fields: ['email', 'name']}, function (req, res) { //FB.setAccessToken(req.query.fb_token); if(!res || res.error) { console.log(!res ? 'error occurred' : res.error); return; } console.log('Post Id: ' + res.id); }); 

How can I get user email and name by passing access token as a query parameter.

Not tested, but according to the docs on npm:

FB.setAccessToken(req.query.fb_token);
FB.api('me', {fields: ['email', 'name'], (req, res) => {
  if(!res || res.error) {
    console.log(!res ? 'error occurred' : res.error);
    return;
  }
  console.log(res.email, res.name);
});

Make sure you know when to use GET and POST, and of course the feed endpoint does not return any email. You just copied that code from the docs, but from the wrong place ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM