小编Luc*_*olo的帖子

使用 google Drive api 上传 Excel 文件

我在使用 Google Drive API 时遇到问题。

我正在尝试使用此 API 上传 Excel 文件,但它不起作用。即使复制 google API 文档也不起作用。

这是我的代码示例:

@Get('teste')
async teste(){
    const keys = require(path.resolve('src', 'files', 'api', 'keys'))
    const client = new google.auth.JWT(
        keys.client_email,
        null,
        keys.private_key,
        ['https://www.googleapis.com/auth/drive.metadata.readonly']
    )

    client.authorize((err, tokens) =>{
        if(err){
            console.log(err)
            return;
        } else{
            this.gdrun(client)
        }
    })

}

gdrun(client){
    const drive = google.drive({version: 'v3', auth: client});

    var fileMetadata = {
        name: 'My Report',
        mimeType: 'application/vnd.google-apps.spreadsheet'
    };
    var media = {
        mimeType: 'application/vnd.ms-excel',
        body: require(path.resolve('src', 'files', 'excel', 'solargroup.xlsx'))
    };
    drive.files.create({
        resource: fileMetadata,
        media: …
Run Code Online (Sandbox Code Playgroud)

javascript excel google-api node.js google-drive-api

3
推荐指数
1
解决办法
2215
查看次数