初学者node.js应用程序使用护照+ googleapis

我正在与Node.js一起尝试使用Google书籍API和护照以及Google策略进行身份validation来制作图书库应用程序。 到目前为止,我可以validation和访问API。 现在可能是一个愚蠢的问题,如何获取数据回收使用我的collections视图? 我可以在身份validation后访问Google数据,然后我需要redirect到集合,但是如何将这些数据构build到新视图中?

app.get('/auth/google', passport.authenticate('google', { scope: ['https://www.googleapis.com/auth/books', 'https://www.googleapis.com/auth/userinfo.profile'] })); app.get('/auth/google/callback', passport.authenticate('google', {failureRedirect: '/'}), function (req, res) { // Successful authentication, get data and redirect to user collection googleapis.discover('books', 'v1').execute(function (err, client) { oath2Client.credentials = { access_token: req.user.accessToken, refresh_token: req.user.refreshToken }; var req1 = client.books.mylibrary.bookshelves.list().withAuthClient(oath2Client); req1.execute(function (err, bookshelves) {}); }); res.redirect('/collection'); }); app.get('/collection', routes.collection, function (req, res) {}); 

你可以做的是你可以将数据存储在一个会话variables,然后从另一个路由获取它。 以下是存储string并从另一个页面访问它的示例:

 //enable session support app.use(express.cookieParser()); app.use(express.session({ secret: 'secret key for signed cookies' })); app.get('/foo', function(req, res) { req.session.property = 'property value'; res.redirect('/bar'); }); app.get('/bar', function(req, res) { //the session variables can be accessed here too res.send(req.session.property); });