【发布时间】:2018-09-09 08:53:52
【问题描述】:
我在 NodeJS 中使用“passport-google-drive”和“passport.js”库,我的目标是列出所有文件和文件夹,并能够下载和上传文件到驱动器。我是能够使用谷歌驱动器对用户进行 0auth 验证,然后我得到 accessToken,用户的个人资料。 之后下一步该做什么?如何使用 accessToken 和用户配置文件列出所有文件和文件夹,并能够从驱动器下载上传文件。
const passport = require('passport');
const GoogleDriveStrategy = require('passport-google-drive').Strategy;
const mongoose = require('mongoose');
const Keys = require('../config/keys.js');
const User = mongoose.model('drive-users');
const prettyjson = require('prettyjson');
passport.use(
new GoogleDriveStrategy(
{
clientID: Keys.DRIVE_CLIENT_ID,
clientSecret: Keys.DRIVE_CLIENT_SECRET,
callbackURL: '/auth/google-drive/callback',
scope : 'https://www.googleapis.com/auth/drive'
},
(accessToken, refreshToken, profile, done) => {
console.log(prettyjson.render(profile));
//what next????
}
)
);
//==================
//routes
//==================
app.get(
'/auth/google-drive',
passport.authenticate('google-drive')
);
app.get(
'/auth/google-drive/callback',
passport.authenticate('google-drive')
);
【问题讨论】:
标签: javascript node.js api google-drive-api passport.js