繁体   English   中英

403通过Google-Drive-RESTAPI v3创建文件夹

[英]403 creating a folder via Google-Drive-RESTAPI v3

我正在尝试使用Google-Drive REST-API创建一个文件夹。 我的问题是响应“权限不足”。

我直接从GDrive-API文档中使用示例代码。 但这行不通。

 fs.readFile('credentials.json', (err, content) => { if (err) return console.log('Error loading client secret file:', err); // Authorize a client with credentials, then call the Google Drive API. authorize(JSON.parse(content), createDir); }); /** * Create an OAuth2 client with the given credentials, and then execute the * given callback function. * @param {Object} credentials The authorization client credentials. * @param {function} callback The callback to call with the authorized client. */ function authorize(credentials, callback) { const {client_secret, client_id, redirect_uris} = credentials.installed; const oAuth2Client = new google.auth.OAuth2( client_id, client_secret, redirect_uris[0]); // Check if we have previously stored a token. fs.readFile(TOKEN_PATH, (err, token) => { if (err) return getAccessToken(oAuth2Client, callback); oAuth2Client.setCredentials(JSON.parse(token)); callback(oAuth2Client); }); } function createDir(auth) { const drive = google.drive({version: 'v3', auth}); var fileMetadata = { 'name': 'Invoice', 'mimeType': 'application/vnd.google-apps.folder' }; drive.files.create({ resource: fileMetadata, fields: 'id' }, function (err, file) { if (err) { // Handle error console.error(err); } else { console.log('Folder Id: ', file.id); } }); } 

注意:读取文件的工作没有任何问题。

我使用了错误的访问范围。 使用“ https://www.googleapis.com/auth/drive ”进行完全访问。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM