【发布时间】:2022-01-25 10:01:30
【问题描述】:
我正在使用 google Sheet api 为个人项目开发 Next JS 应用程序。现在这在我的本地工作完全正常。但是当我将它部署到 Netlify 时,会弹出这个错误。
有人可以提出解决方案吗? 谢谢!
这是我的代码:
import { google } from "googleapis";
export default async function form1(req, res){
if (req.method === 'POST') {
// Process a POST request
console.log("POST hit")
const auth = new google.auth.GoogleAuth({
keyFile: "credentials.json",
scopes: "https://www.googleapis.com/auth/spreadsheets",
})
//create client instancce
const client = await auth.getClient();
//instance of google sheet api
const googleSheets = google.sheets({version: "v4", auth: client});
const spreadsheetId = "*********55653"
//Write rows TO sheet
const {name, email, phone} = req.body;
await googleSheets.spreadsheets.values.append({
auth,
spreadsheetId,
range:"Subs!A:B",
valueInputOption: "USER_ENTERED",
resource: {
values: [
[name, email, phone]
],
}
})
res.send("Success")
} else {
// Handle any other HTTP method
res.status(405)
}
}
【问题讨论】:
-
你是否在 gitignore 中添加了 credentials.json 文件。检查一次文件是否存在于 netlify 中
标签: node.js google-api google-oauth google-sheets-api google-api-nodejs-client