# 是否可以通过 API 获取所有用户的电子邮件？

**URL:** https://meta.discourse.org/t/is-there-a-way-to-get-all-emails-of-users-with-the-api/131077
**Category:** Development
**Tags:** rest-api
**Created:** [2019 年10 月 15 日 16:57 UTC](https://meta.discourse.org/t/is-there-a-way-to-get-all-emails-of-users-with-the-api/131077 "2019-10-15T16:57:12Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### 作者： ![alank](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@alank](https://meta.discourse.org/u/alank)
#### 发布日期： [2019 年10 月 15 日 16:57 UTC](https://meta.discourse.org/t/is-there-a-way-to-get-all-emails-of-users-with-the-api/131077/1 "2019-10-15T16:57:13Z")

</div>

我见过这个链接：[Is there a way to get a user email adress from the API?](https://meta.discourse.org/t/is-there-a-way-to-get-a-user-email-adress-from-the-api/90637)

不过，我们需要通过 Discourse API 在另一个服务中验证某个电子邮件是否存在于 Discourse 站点上。我们可以通过 `/u/search/users.json` 搜索用户名或姓名，但这些接口似乎不会返回电子邮件地址。

那么，您能否搜索或查询所有电子邮件以进行比较？

---

<div class="post-metadata">

### 作者： ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### 发布日期： [2019 年10 月 15 日 17:00 UTC](https://meta.discourse.org/t/is-there-a-way-to-get-all-emails-of-users-with-the-api/131077/2 "2019-10-15T17:00:33Z")

</div>

您可以使用数据浏览器插件创建查询，然后在类似 `SELECT * FROM user_emails` 的查询中调用查询 API。

此外，针对每个用户，还存在一个 `https://meta.discourse.org/u/<username>/emails.json` 端点。

---

<div class="post-metadata">

### 作者： ![alank](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@alank](https://meta.discourse.org/u/alank)
#### 发布日期： [2019 年10 月 15 日 17:04 UTC](https://meta.discourse.org/t/is-there-a-way-to-get-all-emails-of-users-with-the-api/131077/3 "2019-10-15T17:04:28Z")

</div>

是的，我最初问题中包含的链接是“[Discourse Meta](https://meta.discourse.org/u/)/emails.json”，但有没有办法获取所有用户的邮箱？…如果可能的话，我更倾向于使用 API，而不是实现一个允许 SQL 查询的插件。

---

<div class="post-metadata">

### 作者： ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### 发布日期： [2019 年10 月 15 日 17:08 UTC](https://meta.discourse.org/t/is-there-a-way-to-get-all-emails-of-users-with-the-api/131077/4 "2019-10-15T17:08:21Z")

</div>

我们的 API 端点供 Web 应用使用。由于我们在 Web 应用中记录邮件查询，因此不会开放任何用于批量抓取邮件的接口。

目前唯一的方法是使用上述提到的基于数据浏览器的解决方案。

---

<div class="post-metadata">

### 作者： ![alank](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@alank](https://meta.discourse.org/u/alank)
#### 发布日期： [2019 年10 月 15 日 17:18 UTC](https://meta.discourse.org/t/is-there-a-way-to-get-all-emails-of-users-with-the-api/131077/5 "2019-10-15T17:18:13Z")

</div>

为明确起见，我们是通过密钥使用 API 的。我理解前端不会拥有相同的权限，但 API 难道不能拥有访问权限吗？

提供更多细节：我们有一个应用程序和 Discourse 论坛，两者都通过 Auth0 SSO 进行授权。然而，如果有人登录我们的应用程序，我们希望确保他们在 Discourse 上拥有账户（并引导他们访问该链接）。也许如果用户先访问我们的网站，这并不是检查 Discourse 是否已注册该邮箱的最佳方式。这是一个 Discourse 链接，用于在邮箱尚未注册的情况下提供指引。

---

<div class="post-metadata">

### 作者： ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### 发布日期： [2019 年10 月 15 日 17:32 UTC](https://meta.discourse.org/t/is-there-a-way-to-get-all-emails-of-users-with-the-api/131077/6 "2019-10-15T17:32:51Z")

</div>

> [@alank](#):
>
> SSO 授权

如果您使用的是 _真正的_ [Discourse SSO](https://meta.discourse.org/t/official-single-sign-on-for-discourse-sso/13045?u=falco)，您可以通过 SSO 负载中传递的外部唯一 ID，使用 `GET https://example.com/u/by-external/<EXTERNAL_ID>` 来查询用户是否存在。

---

<div class="post-metadata">

### 作者： ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### 发布日期： [2023 年6 月 22 日 18:04 UTC](https://meta.discourse.org/t/is-there-a-way-to-get-all-emails-of-users-with-the-api/131077/7 "2023-06-22T18:04:59Z")

</div>



---

<div class="post-metadata">

### 作者： ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### 发布日期： [2023 年6 月 23 日 14:19 UTC](https://meta.discourse.org/t/is-there-a-way-to-get-all-emails-of-users-with-the-api/131077/8 "2023-06-23T14:19:59Z")

</div>


