在NEXTJS中使用npm谷歌趋势api时遇到问题
我不确定这是不是正确的方法。
我创建了一个新的API路由。
http://localhost:3000/api/trendshttp://localhost:3000/api/trends
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发布于 2021-09-17 11:41:49
尝尝这个。这里我使用的是TypeScript,如果你使用的是Javascript,请根据需要编辑代码。
import type { NextApiRequest, NextApiResponse } from 'next'
import googleTrendsApi from "google-trends-api";
type Data = {
name: string
}
export default function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
const data = googleTrendsApi
.interestOverTime({ keyword: ["Women's march", "Trump Inauguration"] })
.then(function (results: any) {
res.status(200).json(results)
});
}https://stackoverflow.com/questions/69221746
复制相似问题