更新时间:2023-12-01 13:46:40
可以在没有 OAuth
或 API Keys
的情况下写入电子表格.您需要使用 Service Account Keys
.
这是我为我的 Node.js 环境所做的.
提供新的私钥
JSON
.服务帐户密钥
包括一个client_email
.client_email
对该文档具有写入权限使用以下代码进行身份验证
让 jwtClient = new google.auth.JWT(client_email, null, private_key, ["https://www.googleapis.com/auth/spreadsheets",]);//验证请求jwtClient.authorize(function(err, tokens) {//此时身份验证完成,您现在可以使用 `jwtClient`//读取或写入电子表格});
client_email
和 private_key
是 service account key
可以在此处找到更详细的说明.http://isd-soft.com/tech_blog/accessing-google-apis-using-service-account-node-js/ 此外,所有功劳都归于此页面.
I have created Google Spreadsheet, and given edit access to all (can edit even without login).
Here is the link. I would like to update this sheet with Google Spreadsheet API. But I am getting error. My requirement is update the sheet thru API even without access credential.
It is possible to write to spreadsheet without OAuth
or API Keys
. You need to use Service Account Keys
.
Here is what I did for my Node.js environment.
Furnish a new private key
JSON
when it asks you how to download the key.service account key
you have just generated includes a client_email
.
client_email
to have write access on this documentUse the following code to authenticate
let jwtClient = new google.auth.JWT(client_email, null, private_key, [
"https://www.googleapis.com/auth/spreadsheets",
]);
//authenticate request
jwtClient.authorize(function(err, tokens) {
// at this point the authentication is done you can now use `jwtClient`
// to read or write to the spreadsheet
});
client_email
and private_key
are part of the service account key
A more detailed description can be found here. http://isd-soft.com/tech_blog/accessing-google-apis-using-service-account-node-js/ Also, all credit goes to this page.