访问被拒绝创建电子表格谷歌节点API

时间:2017-08-22 08:17:47

标签: node.js api google-sheets

我正在使用google node API生成电子表格。我使用的第三方库是官方库(https://github.com/google/google-api-nodejs-client)。以下是我用来生成电子表格的代码:

var sheets = google.sheets('v4');

sheets.spreadsheets.create({
    auth: auth,
    resource: {
        properties:{
            title: "Google export"
        }
    }
}, (err, response) => {
    if (err) {
        console.log('The API returned an error: ' + err);
        return;
    } else {
        console.log("Added");
        res.send(response);
    }
});

它工作正常并生成工作表,当我显示响应对象时,我得到了电子表格的链接:

  

spreadsheetUrl:“https://docs.google.com/spreadsheets/d/1XS_QHxPUQcGqZGAzFHkHZV-RSKsv5IpJazcjVpLTYkk/edit

但是当我尝试在浏览器中打开它时,我不能:You need permission。 问题是,如果我点击Request access按钮,我认为它实际上是从我的凭证(user@project-174309.iam.gserviceaccount.com)向client_email发送请求,所以它没有'工作。 如果我以编程方式打开电子表格,它可以正常工作......

有谁知道如何在浏览器中打开生成的电子表格?

1 个答案:

答案 0 :(得分:1)

这是一个解决方案:https://github.com/google/google-api-nodejs-client/issues/804#issuecomment-327931203

需要使用Google Drive API为此文件授予权限