Javascript 用于restfulapi的googledrive

Javascript 用于restfulapi的googledrive,javascript,node.js,api,google-drive-api,passport.js,Javascript,Node.js,Api,Google Drive Api,Passport.js,我正在NodeJS中使用“passport google drive”和“passport.js”库,我的目标是列出所有文件和文件夹,并能够下载和上传文件到驱动器。我能够使用google drive对用户进行0auth,然后我将获得用户的acessToken和个人资料。 在那之后下一步要做什么?如何使用acessToken和用户配置文件列出所有文件和文件夹,并能够从驱动器下载上载文件 const passport=require('passport'); const GoogleDriveSt

我正在NodeJS中使用“passport google drive”和“passport.js”库,我的目标是列出所有文件和文件夹,并能够下载和上传文件到驱动器。我能够使用google drive对用户进行0auth,然后我将获得用户的acessToken和个人资料。 在那之后下一步要做什么?如何使用acessToken和用户配置文件列出所有文件和文件夹,并能够从驱动器下载上载文件

const passport=require('passport');
const GoogleDriveStrategy=require('passport-google-drive')。策略;
const mongoose=require('mongoose');
const Keys=require('../config/Keys.js');
const User=mongoose.model('drive-users');
const prettyjson=require('prettyjson');
passport.use(
谷歌新战略(
{
clientID:Keys.DRIVE\u CLIENT\u ID,
clientSecret:Keys.DRIVE\u CLIENT\u SECRET,
callbackURL:“/auth/google drive/callback”,
范围:'https://www.googleapis.com/auth/drive'
},
(accessToken、refreshToken、profile、done)=>{
log(prettyjson.render(profile));
//接下来呢????
}
)
);
//==================
//路线
//==================
app.get(
“/auth/google drive”,
passport.authenticate('google-drive'))
);
app.get(
“/auth/google drive/callback”,
passport.authenticate('google-drive'))

);下面的代码显示了如何使用配置文件信息为用户提供个性化功能

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');

function extractProfile (profile) {
    let imageUrl = '';
    if (profile.photos && profile.photos.length) {
      imageUrl = profile.photos[0].value;
    }
    return {
      id: profile.id,
      displayName: profile.displayName,
      image: imageUrl
    };
  }

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));
          // Extract the minimal profile information we need from the profile object
          // provided by Google
          done(null, extractProfile(profile));
          }
       )
   );

    // Typically, this will be as simple as storing the user ID when serializing, and finding
    //  the user by ID when deserializing.
    passport.serializeUser( function (user, done) {
        done(null, user);
    });

    passport.deserializeUser( function (obj, done) {
        done(null, obj);
    });

   //==================
   // add your routes here
   //==================


   app.get(
    '/auth/google-drive',
     passport.authenticate('google-drive')
   );

  app.get(
    '/auth/google-drive/callback',
     passport.authenticate('google-drive')
   );
还有一个使用Passport.js。这将帮助您了解使用Passport.js库的用户的身份验证

您还可以使用Google Drive for Resful API读取Node.js的链接