Node.js 执行回调并将数据保存到mysql数据库时出现问题

Node.js 执行回调并将数据保存到mysql数据库时出现问题,node.js,google-api,google-api-nodejs-client,Node.js,Google Api,Google Api Nodejs Client,我正在尝试使用google plus api进行身份验证,并尝试在google plus api的回调函数中保存google用户详细信息,但由于某些原因,我无法将google plus api响应中的值传递给回调请求。 Router.js中的代码片段 router.get("/auth/google", passport.authenticate('google', { scope: ['profile','email'] })); router.get("/aut

我正在尝试使用google plus api进行身份验证,并尝试在google plus api的回调函数中保存google用户详细信息,但由于某些原因,我无法将google plus api响应中的值传递给回调请求。 Router.js中的代码片段

router.get("/auth/google", passport.authenticate('google', { scope: ['profile','email'] }));
router.get("/auth/google/callback" , passport.authenticate('google') , googleInsert);
User.controller.js中的代码段

   const {
  getGoogleUserByEmail,
  createGoogleUser,
} = require("./user.service.js");

module.exports = {
  googleInsert: (req, res) => {
    body = req.body;
    body.googleId = req.body.profile.id;
    body.firstName = req.body.profile.name.givenName;
    body.lastName = req.body.profile.name.familyName;
    body.email = req.body.profile.emails[0].value;
    body.photoUrl = req.body.profile.photos[0].value;
    //const salt = genSaltSync(10);
    //body.password = hashSync(body.password, salt);
    //verify if email id exists
    getGoogleUserByEmail(body.email, (err, results) => {
      if (err) {
        console.log(err);
      }
      //Email id already registered and exists in db
      if (results) {
        console.log("Google Email already exists");
        return res.status(409).json({
          success: 0,
          data: "Google Email already exist",
        });
      }
      console.log(
        "Google Email id is not registered, proceed with Google User Insert"
      );
      if (!results) {
        createGoogleUser(body, (err, createResults) => {
          console.log(body);
          if (err) {
            console.log(err);
            return res.status(500).json({
              success: 0,
              message: "Database connection error",
            });
          }
          if (createResults.affectedRows == 1) {
            console.log("inside succcess is 1");
            //Insert into UserRole Table
            createUserRole(
              createResults.insertId,
              (body.role_id = 2),
              (err, results) => {
                console.log(results);
                if (err) {
                  console.log(err);
                  return res.status(500).json({
                    success: 0,
                    message: "DB error",
                  });
                }
                if (!err) {
                  console.log("Google User created successfully");
                  return res.status(200).json({
                    success: 1,
                    data: createResults,
                  });
                }
              }
            );
          }
        });
      }
    });
  },
};
Passport.js

const passport = require("passport");
const GoogleStrategy = require("passport-google-oauth20").Strategy;
const keys = require('../config/keys');

passport.use(
    new GoogleStrategy(
      {
        clientID: process.env.clientID,
        clientSecret: process.env.clientSecret,
        callbackURL: "http://localhost:1111/api/users/auth/google/callback",
        //passReqToCallback: true
      },
      (accessToken, refreshToken, profile, callback) => {
        console.log("access token", accessToken);
        console.log("refresh token", refreshToken);
        console.log("profile", profile);
        console.log("callback", callback);
      }
    )
  );
我遇到的问题是,我不确定如何从google身份验证中获取用于回调请求的值,也不确定回调是否有效。在我从GooglePlus api客户端屏幕选择电子邮件id后,它进入无限循环,没有数据被插入数据库

body = req.body;
        body.googleId = req.body.profile.id;
        body.firstName = req.body.profile.name.givenName;
        body.lastName = req.body.profile.name.familyName;
        body.email = req.body.profile.emails[0].value;
        body.photoUrl = req.body.profile.photos[0].value;

当google plus于2019年关闭时,google plus api停止使用。你需要打电话给google people api以获取数据。我认为这不是问题所在。我正在使用tutorial(),它的源代码位于git。请检查您是否也遇到同样的问题,以及您是否知道如何解决它。很抱歉,我无法帮助您学习第三方教程。我建议您联系创建这些教程的公司。我的经验对谷歌的官方文档非常敏感。我可以告诉你,你正在关注的教程是2017年7月12日创建的,这是在Google+关闭之前,你是否认为它不再有效。同样,一个好主意是联系作者。