如果我在Google中创建了一个文档并键入了一些文本,那么我以后就可以将=>发布到Web文件中,并获得一个指向公共网页- google文档的样式的链接以及一个嵌入链接。
这是手动完成的。如何使用Node.JS服务器脚本(例如,使用服务帐户)使用Goolgle驱动器API自动完成此操作?我在他们的文档里找不到任何关于这个东西的东西,这有可能吗?我需要做一个谷歌脚本来代替吗?有这个可能吗?
发布于 2019-12-03 05:13:33
从你的提问和答复中,我可以这样理解。如果我的理解是正确的,那么这个答案呢?请把这看作是几个可能的答案之一。
用法:
为了使用下面的示例脚本,请执行以下流程。
这样,Google文档就会发布到web上,您可以在控制台上看到已发布的URL。
示例脚本:
const { google } = require("googleapis");
// Please set the email and private key of service account.
const auth = new google.auth.JWT(
"### email of service account ###",
null,
"### private key of service account ###" ,
["https://www.googleapis.com/auth/drive"]
);
const fileId = "###"; // Please set the file ID.
const drive = google.drive({ version: "v3", auth });
const body = {
resource: {
published: true,
publishedOutsideDomain: true,
publishAuto: true
},
fileId: fileId,
revisionId: 1
};
drive.revisions.update(body, err => {
if (err) {
console.error(err);
return;
}
console.log(`https://docs.google.com/document/d/${fileId}/pub`);
});"-----BEGIN PRIVATE KEY-----\n###\n-----END PRIVATE KEY-----\n"一样设置私钥。注意:
https://docs.google.com/document/d/${fileId}/pub。在本例中,使用文件ID。因为不幸的是,在当前阶段,像https://docs.google.com/document/d/e/2PACX-###/pubhtml这样的URL无法被Google检索。参考资料:
https://stackoverflow.com/questions/59148718
复制相似问题