Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/Noembed/Provider/Twitter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package Noembed::Provider::Twitter;

use parent 'Noembed::oEmbedProvider';

sub patterns { 'https?://(?:www|mobile\.)?twitter\.com/(?:#!/)?([^/]+)/status(?:es)?/(\d+)' }
# Matches both twitter.com and x.com post URLs (including mobile and hash-bang variants)
sub patterns { 'https?://(?:www|mobile\.)?(?:twitter|x)\.com/(?:#!/)?([^/]+)/status(?:es)?/(\d+)' }

sub build_url {
my ($self, $req) = @_;
my $captures = $req->captures;
# Normalize to twitter.com — publish.x.com/oembed does not reliably resolve x.com-domain URLs
$req->url(sprintf "https://twitter.com/%s/status/%s", @$captures);
$self->SUPER::build_url($req);
}

sub provider_name { "Twitter" }
sub oembed_url { "https://publish.twitter.com/oembed" }
sub provider_name { "X (formerly Twitter)" }
sub oembed_url { "https://publish.x.com/oembed" }

1;