【发布时间】:2021-09-17 19:41:48
【问题描述】:
在 NEXTJS 中使用 npm google 趋势 api 时遇到问题
不确定这是否是正确的方法。
我创建了一个新的 API 路由。
http://localhost:3000/api/trends
http://localhost:3000/api/趋势
import googleTrendsApi from "google-trends-api";
const handler = async (res, req) => {
const data = await googleTrendsApi
.interestOverTime({ keyword: ["Women's march", "Trump Inauguration"] })
.then(function (results) {
console.log("These results are awesome", results);
});
res.status(200).json({ data: data });
};
我收到一个错误提示
TypeError: res.status is not a function
【问题讨论】:
-
handler的签名应该是(req, res),res是第二个参数而不是第一个 - 顺序很重要。req.status(来自第一个参数)不存在因此错误的原因。
标签: javascript reactjs next.js google-trends