Configure Twitter login and rich embeds for Discourse

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

X Configuration

  1. Head over 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. If you would like to have rich embeds on your forum you’ll need at least a Basic plan for X Dev. Rich embeds will not work with the Free X Dev plan.
  3. After completing the agreement and policy requirements you’ll be taken to the X dev dashboard where a default project and app will be created.

Update your default Project and App

  1. Under your default project title, click the Settings tab followed by the Edit button.
  2. Edit the project name, use, and description (optional) followed by clicking the Save button. If you are using an account with a Basic or Pro plan please select Embedding_Tweets_in_a_website.
  3. Click the Overview button below the project title and scroll down to the Apps section.
  4. In the Apps section, click the cogwheel icon, or App_Settings, to the right of your app name.
  5. Click the Edit button displayed below the name and update the app name, icon, and description. Be sure to save your changes.
  6. Select the Set up button under User Authentication Settings and 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
  7. Click Save
  8. Click the Keys_and_Tokens tab below the app title and select the Regenerate button for API Key and Secret.
  9. In another tab, head to your Discourse forum and complete the steps listed under the Discourse Configuration section below.

If you already have a X Dev account please use the steps below to create a new project.

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 like: “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’s 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.


Rebaking Posts / Rebuild HTML

:warning: It’s important to know that rebaking or using the rebuild HTML button on posts that contain tweets will re-pull the tweet(s) and count them towards your monthly tweet cap usage.

Last edited by @jessii 2024-05-31T22:18:18Z

Check documentPerform check on document:
72 Likes

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 Likes

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 Like

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 Likes

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 Likes

March 2020

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

16 Likes

Twitter, Doesn’t seem to work

Cannot add Create an app

1 Like

It works for me

image

and looking at https://api.twitterstat.us/ the Developer Portal is ok.

You are probably using some extension that blocks social media, tracking or something similar. Try logging in from an anonymous window with all extensions disabled

4 Likes

The guide has been updated

7 Likes

I hope this is the right place to ask this question. I see from https://try.discourse.org/ that registration by Twitter leads to the following message:

This application will be able to:

See Tweets from your timeline (including protected Tweets) as well as your Lists and collections.
See your Twitter profile information and account settings.
See accounts you follow, mute, and block.
See your email address.

Is it possible to set it up where it sees the minimum amount of information necessary - name and email address I think?

1 Like

This is already the minimum information required by Twitter.

As you can see from the guide, the only thing we require from Twitter is the user email that Discourse needs to create the user account. Everything else is the basic settings decided by Twitter selecting “Read only” in the App Permission section.

6 Likes

Hi I’m trying to embed a reply to a tweet.

The embed should look like this.

I just get the reply. Not the original Tweet too.
Is this just the way it works on Discourse or am I doing something wrong?

2 Likes

I don’t use Twitter, but I assume the reply link is different from the original tweet’s link. Therefore, you are only linking to the reply. Does linking to the original tweet also include the first reply or just the original tweet?

1 Like

Hi Jimpas,

No the idea is that if you embed the reply you can choose to have the original tweet above it as in the pic. So the reply has context.
I quite like the styling too.

I’m just getting the reply.
A workaround is two embeds.

1 Like

That is indeed a work-around. But how can you choose to have the original tweet above a reply? So how would one “choose”? I do see at times someone posts on another website that the original tweet has the first reply to it. :thinking:

I am noticing the same registration issue as well. When I try using a test account, and Twitter even states at register that email is being accessed, the email account is not prefilled into the account registration form after completing the authentication handshake with Twitter, and it is also showing “user_1” for the prefilled username. Rich embeds are not working as well.

1 Like

Not panic and wait patiently. The Discourse team reads every post very carefully, so I am sure they are already on top of this. :slight_smile:

2 Likes

@Hifihedgehog and @dnfoz this has been assigned out, we will review it shortly. Does anyone else have issues with setting this up and logging in?

4 Likes

Any update ?? I have the same issue

1 Like