NEXTJS google 趋势 API
NEXTJS google trend API
在 NEXTJS
中使用 npm google 趋势 api 时遇到问题
不确定这样做是否正确。
我创建了一条新的 API 路线。
http://localhost:3000/api/trends
http://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
试试这个。这里我使用的是 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)
});
}
在 NEXTJS
中使用 npm google 趋势 api 时遇到问题不确定这样做是否正确。
我创建了一条新的 API 路线。
http://localhost:3000/api/trends
http://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
试试这个。这里我使用的是 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)
});
}