> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Trends 集成

> 使用 LangChain JavaScript 集成 Google Trends 工具。

Google Trends 工具允许您的代理使用来自 SerpApi 的 Google Trends API 来检索和分析搜索兴趣数据。
这对于了解热门话题、地区搜索兴趣以及搜索词的历史流行度非常有用。

有关 API 详情，请参阅 [Google Trends API 文档](https://serpapi.com/google-trends-api)

SerpApi 会缓存查询，因此第一次查询会较慢，而后续相同的查询会很快。
偶尔，相关查询可能无法正常工作，但随时间变化的兴趣数据应该没问题。您可以在 [SerpApi playground 中检查您的查询](https://serpapi.com/playground?engine=google_trends\&q=monster\&data_type=RELATED_QUERIES)。

## 设置

要使用此工具，您需要配置对 SerpApi 的 Google Trends API 的访问权限。

从 [SerpApi](https://serpapi.com/users/sign_in) 获取 API 密钥。

然后，将您的 API 密钥设置为 `process.env.SERPAPI_API_KEY`，或将其作为 `apiKey` 构造函数参数传入。

## 用法

<Tip>
  有关安装 LangChain 包的一般说明，请参阅[此部分](/oss/javascript/langchain/install)。
</Tip>

```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install @langchain/openai @langchain/community @langchain/core
```

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { SERPGoogleTrendsTool } from "@langchain/community/tools/google_trends";

export async function run() {
  const tool = new SERPGoogleTrendsTool();

  const res = await tool.invoke("Monster");

  console.log(res);
}
```

## 相关内容

* 工具[概念指南](/oss/javascript/langchain/tools)
* 工具[操作指南](/oss/javascript/langchain/tools)

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档](/use-these-docs)通过 MCP 连接到 Claude、VSCode 等，以获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/javascript/integrations/tools/google_trends.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
