> ## 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.

# Mastodon 集成

> 使用 LangChain Python 与 Mastodon 文档加载器集成。

> [Mastodon](https://joinmastodon.org/) 是一个联邦式的社交媒体和社交网络服务。

此加载器使用 `Mastodon.py` Python 包，从一组 `Mastodon` 账户的“嘟文”中获取文本。

默认情况下，可以查询公共账户而无需任何身份验证。如果查询非公共账户或实例，则必须为你的账户注册一个应用程序以获取访问令牌，并设置该令牌和你的账户的 API 基础 URL。

然后，你需要以 `@account@instance` 格式传入你想要提取的 Mastodon 账户名。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.document_loaders import MastodonTootsLoader
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU  Mastodon.py
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
loader = MastodonTootsLoader(
    mastodon_accounts=["@Gargron@mastodon.social"],
    number_toots=50,  # 默认值为 100
)

# 或者设置访问信息以使用 Mastodon 应用。
# 请注意，访问令牌可以传递给构造函数，
# 也可以设置环境变量 "MASTODON_ACCESS_TOKEN"。
# loader = MastodonTootsLoader(
#     access_token="<MASTODON 应用的访问令牌>",
#     api_base_url="<MASTODON 应用实例的 API 基础 URL>",
#     mastodon_accounts=["@Gargron@mastodon.social"],
#     number_toots=50,  # 默认值为 100
# )
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
documents = loader.load()
for doc in documents[:3]:
    print(doc.page_content)
    print("=" * 80)
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
<p>离开这里回到现实很艰难。而且有些人就住在这里！我确信有缺点，但对我来说现在听起来相当不错。</p>
================================================================================
<p>我希望我们能在这里多待一会儿，但该回家了 🥲</p>
================================================================================
<p>蜜月的最后一天。而且今天是 <a href="https://mastodon.social/tags/caturday" class="mention hashtag" rel="tag">#<span>caturday</span></a>！这只可爱的虎斑猫来餐厅讨食物，得到了一些鸡肉。</p>
================================================================================
```

嘟文文本（文档的 `page_content`）默认是 Mastodon API 返回的 HTML 格式。

***

<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/python/integrations/document_loaders/mastodon.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
