実際のところ
トークンの生成
前回のサンプルと異なり、Scopeを変更しないといけません
ファイルにアクセスするのは"https://www.googleapis.com/auth/drive.file"
具体的にはこんな感じで書き換わるはず
const SCOPES = ['https://www.googleapis.com/auth/drive.file'];
スクリプト
関数部分のみ抜き出すと、こんな感じに
function uploadFile (auth) { const drive = google.drive({version: 'v3', auth}); var fileMetadata = { 'name': 'sample.txt' }; var media = { mimeType: 'plane/text', body: fs.createReadStream('sample.txt') }; drive.files.create({ resource: fileMetadata, media: media, fields: 'id' }, function (err, file) { if (err) { // Handle error console.error(err); } else { console.log('File Id: ', file.id); } }); }