[英]How to use passport-facebook with MySQL?
I'm having difficulty setting up passport-facebook with MySQL. 我在使用MySQL设置passport-facebook时遇到了困难。
Everywhere I look I find mongodb, and using mongodb one can post the profile._json object into the database but with MySQL you can't. 无论我到哪里,我都会找到mongodb,并且使用mongodb可以将profile._json对象发布到数据库中,但是使用MySQL则不能。
passport.use(new FacebookStrategy({
clientID : "",
clientSecret : "",
callbackURL : ""
}), function (accessToken, refreshToken, profile, done){
db.query("SELECT * FROM users WHERE facebook_id = ?", [profile.id], function(err, user){
if (err){
return done(err);
}
else if (user.length == 0){
var name = profile.displayName;
var email = profile.emails[0].value;
var username = profile.username;
var provider = "facebook";
var facebook = profile._json;
db.query("INSERT INTO users (name, email, username, provider, token) VALUES (?, ?, ?, ?, ?)",
[name, email, username, provider, /* profile._json?? */], function(err){
})
}
else{
return done(err, user);
}
});
});
What is the contents of profile._json that need to be saved and their types so that I can create fields in MySQL database? 需要保存的profile._json的内容及其类型是什么,以便我可以在MySQL数据库中创建字段?
Is there a possibility that maybe I should set up mongodb and save that info there and use MySQL databse for the rest? 是否有可能我应该设置mongodb并将信息保存在那里并使用MySQL数据库进行其余的工作? I am also using google authentication for my API.
我也在为我的API使用谷歌身份验证。
Try this 尝试这个
let user= {Facebook_ID: profile.id, First_Name: profile.displayName, FB_Private_Chat_ID: '000001100'};
mysqlconnection.query('INSERT INTO users SET ?', user, (err, res) => {
if(err) throw err;
console.log('Last insert ID:', profile.id);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.