blu*_*yke 5 javascript node.js web google-drive-api
如果我在 Google 云端硬盘中创建文档并输入一些文本,我稍后可以转到 file => Publish to the Web 并获取指向google 文档的公共网页样式的链接以及嵌入链接。
这就是手动完成的方式。如何使用Goolgle Drive API通过Node.JS 服务器脚本(例如,使用服务帐户)自动执行此操作?我在他们的文档中找不到有关此特定事物的任何信息,这可能吗?我需要制作一个谷歌脚本吗?这可能吗?
从你的问题和回复评论中,我可以这样理解。如果我的理解是正确的,这个答案怎么样?请将此视为几个可能答案之一。
为了使用以下示例脚本,请执行以下流程。
这样,Google 文档就发布到了网络上,您可以在控制台看到发布的 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`);
});
Run Code Online (Sandbox Code Playgroud)
"-----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-###/pubhtmlGoogle API无法检索到类似的URL。| 归档时间: |
|
| 查看次数: |
2023 次 |
| 最近记录: |