配置 Discourse 的 X 登录和 rich embeds

:bookmark: This guide explains how to set up Twitter login and rich embeds for your Discourse forum.

:person_raising_hand: Required user level: Administrator

:warning: In order for rich embeds to work properly, a Basic plan or higher for X Dev is mandatory. Rich embeds will not work with the Free X Dev plan.

X Configuration

  1. Go to the Developer Portal on X.

  2. Choose between a Free, Basic, or Pro X Dev plan and complete the developer agreement and policy requirements.

  3. After completing the agreement and policy requirements, you’ll be taken to the X dev dashboard.

Create a new project

  1. On your X Dev dashboard, click + Add Project.

  2. Complete the requested information:

    • Your project name
    • Use case. If you are using an account with a Basic or Pro plan, please select Embedding_Tweets_in_a_website.
    • Your project description (e.g., “Enable Twitter login and embeds on a Discourse forum”).
    • Select Production for the app environment. Note you may not be prompted to select the app environment.
    • Your app name
  3. You will be shown your API Key and API Key Secret. Please write these down so you can add them to your Discourse forum later.

  4. Click the App Settings button on the bottom right.

  5. Scroll down to the User Authentication Settings section and click the Set up button. Update the following fields:

    • App Permission → Read and enable Request_email_from_users
    • Type of App → Web App, Automated App or Bot
    • App info →
      • Callback URL / Redirect URL: https://yourdiscourseforum.com/auth/twitter/callback
      • Website URL: https://yourdiscourseforum.com
      • Terms of service: https://yourdiscourseforum.com/tos
      • Privacy Policy: https://yourdiscourseforum.com/privacy

  6. Click Save.

Discourse configuration

  1. Head over to your Discourse forum and enter the admin panel.

  2. Click the Settings button and choose Login to find the Twitter-related settings:

  3. Enable the enable_twitter_logins setting.

  4. Copy and paste the API Key from X into the twitter_consumer_key setting.

  5. Copy and Paste the API Key Secret from X into the twitter_consumer_secret setting.

  6. Click the green checkmark to save the changes.

Users should now be able to log into your forum using their Twitter Account.

Rich Embeds

The above steps also apply if you want to enable “rich embedding” which allows displaying tweets with their media (images video, etc). If you want rich embeds but don’t need Twitter login, simply uncheck enable twitter logins and leave the consumer key and secret intact.

:warning: Rebaking or rebuilding HTML for posts with tweets will re-fetch those tweets, counting against your monthly tweet cap.

Additional resources

Last edited by @sam 2026-03-18T04:43:33Z

Check documentPerform check on document:
75 个赞

Note that the “Callback URL” field is now mandatory. If you omitted it in your setup, Twitter login will fail with a 403 unauthorized error.

Also note that if you have any extra spaces at the beginning or end of your callback urls, auth will fail. You can find other discussions about this change on the Twitter Community.

13 个赞

Just noticed we were getting the same error on our site with Twitter auth. I noticed Twitter has a new process for authorizing developer apps, so we are going through the approval process. Not sure if it is related, or if this problem has just been in place for a long time now.

1 个赞

I setup my callback URL like this on Twitter, but still getting the same error.
https://www.helloforos.com/auth/twitter

Does this look like the right format? What do you guys use?

I’m going to try it again tomorrow in case there’s some caching issue with Twitter

Anyone else have success with Twitter login?

@charleswalter That callback url is wrong. It should be:

7 个赞

that did the trick. Thx for calling that out.

I do recommend that those who haven’t applied on developer.twitter.com for their Twitter app, to do so.

For the near future, you can continue to manage existing apps here on apps.twitter.com. However, we will soon retire this site and consolidate all developer tools, API access, and app management within the developer portal at developer.twitter.com. You will be able to access and manage existing apps through that portal when we retire this site.

5 个赞

March 2020

Guide completely rewritten because Twitter has changed the whole process … another time :sweat_smile:

16 个赞

Twitter 似乎无法正常工作

无法添加“创建应用”

1 个赞

在我这里可以正常工作

查看 https://api.twitterstat.us/,开发者门户正常。

您可能使用了某些阻止社交媒体、追踪或其他类似功能的扩展程序。请尝试在禁用所有扩展程序的匿名窗口中登录。

4 个赞

指南已更新

7 个赞

我希望这里是提出这个问题的正确地方。我从 https://try.discourse.org/ 看到,通过 Twitter 注册会导致出现以下消息:

此应用程序将能够:

查看您时间线中的推文(包括受保护的推文)以及您的列表和收藏夹。
查看您的 Twitter 个人资料信息和账户设置。
查看您关注、静音和屏蔽的账户。
查看您的电子邮件地址。

是否可以将其设置为仅获取必要的最少信息——我认为是姓名和电子邮件地址?

1 个赞

这已经是 Twitter 要求的最低信息了。

正如指南所示,我们从 Twitter 获取的唯一信息是 Discourse 用于创建用户账户的用户邮箱。其余内容均为 Twitter 在“应用权限”部分选择“只读”后确定的基本设置。

7 个赞

你好,我正尝试嵌入一条推文回复。

嵌入效果应如下所示:

但我只能看到回复内容,看不到原始推文。这是 Discourse 的固有行为,还是我操作有误?

2 个赞

我不使用 Twitter,但我推测回复链接与原始推文的链接是不同的。因此,你只是链接到了该回复。那么,链接到原始推文时,是只包含原始推文,还是也会包含第一条回复?

1 个赞

你好 Jimpas,

不,想法是如果你嵌入回复,可以选择像图片中那样在回复上方显示原始推文。这样回复就有了上下文。

我也很喜欢这种样式。

我目前只是在获取回复内容。
一个变通方法是使用两个嵌入。

1 个赞

这确实是一种变通方案。但如何设置让原始推文显示在回复上方呢?也就是说,该如何“选择”?我有时看到有人在其他网站上发帖,显示原始推文下方附带了第一条回复。:thinking:

我也遇到了同样的注册问题。当我尝试使用测试帐户时,Twitter 在注册时甚至会显示正在访问电子邮件,但在与 Twitter 完成身份验证握手后,电子邮件帐户不会预先填入帐户注册表单,并且预填的用户名也显示为“user_1”。富嵌入式内容也无法正常工作。

1 个赞

不要惊慌,耐心等待。Discourse 团队会非常仔细地阅读每一篇帖子,所以我相信他们已经处理好了。:slight_smile:

2 个赞

@Hifihedgehog@dnfoz 已分配此问题,我们将尽快进行审查。是否还有其他人遇到设置和登录问题?

4 个赞

有更新吗??我遇到了同样的问题

1 个赞