百度指数 Node.js SDK
因为超过24小时,token 就会失效,必须去百度指数官网获取新的 token
建议用户自己保存 token,并在24小时内请求刷新 token 接口
Node.js 版本 >= 18
npm install --save @wddv/baidu-index
// 初始化实例
const baiduIndex = new BaiduIndex(
process.env.BAIDU_TOKEN!,
process.env.BAIDU_NAME!
);
// 创建任务
const { taskId } = await baiduIndex.createTask({
datasource: "search",
dateRange: {
start: "2024-04-01",
end: "2024-04-01",
},
device: ["all"],
region: {
province: [],
city: [],
isAll: true,
},
keyword: ["小米"],
});
// 获取任务结果
const result = await baiduIndex.getResult(taskId);
console.log(result);