mpratt / Embera

A Oembed consumer library, that gives you information about urls. It helps you replace urls to youtube or vimeo for example, with their html embed code. It has advanced features like offline support, responsive embeds and caching support.
MIT License
335 stars 59 forks source link

Twitter embeds don't work on production #99

Closed johncarter- closed 1 year ago

johncarter- commented 1 year ago

Thanks for such a great package.

I am using Laravel, locally using Laravel Sail and in production using a Laravel Forge provisioned Digital Ocean droplet.

I am running this code:

Illuminate\Support\Facades\Artisan::command('embed', function () {
    $embera = new \Embera\Embera();

    // $testUrl = 'https://www.youtube.com/watch?v=J---aiyznGQ'; // ๐Ÿ‘Œ
    // $testUrl = 'https://vimeo.com/374131624'; // ๐Ÿ‘Œ
    // $testUrl = 'https://twitter.com/KYVENetwork/status/1655919857685221376?s=20'; // ๐Ÿ’ฉ
    $testUrl = 'https://twitter.com/Interior/status/507185938620219395'; // ๐Ÿ’ฉ

    $embedUrlData = $embera->getUrlData($testUrl);

    dump($embedUrlData);
});

It seems that Twitter embeds return an empty array every time on production, but work locally.

Does you have any suggestions why that could be?

Thanks again.

johncarter- commented 1 year ago

Oh, mercy!

https://github.com/oscarotero/Embed/issues/518#issuecomment-1585568740

mpratt commented 1 year ago

Hi @johncarter Yes, Indeed there seems to be a problem with some hosting providers. I had a report coming from German servers having the same problem adn while doing the debug we found this instances where something similar happened:

https://twittercommunity.com/t/oembed-responses-are-returns-with-code-404/136813 (April 2020) https://twittercommunity.com/t/oembed-404/167966 (Mรคrz 2022) https://twittercommunity.com/t/issue-with-twitter-oembed-api-when-accessed-from-digitalocean-droplets/194215 (May 2023)

Lets see if twitter responds

mpratt commented 1 year ago

There seems to be a solution to this problem:

Given the ip address ranges described here: https://developer.twitter.com/en/blog/product-news/2022/updated-source-ip-address-range

You need to allow all TCP connections from those IP ranges.

https://300m.com/security/twitter-oembed-broken-on-digitalocean/

Let me know if this works for you.

johncarter- commented 1 year ago

I can confirm the following works:

  1. Go to Digital Ocean control panel > Networking > Firewalls (tab) > Create Firewall

  2. Add the following rules: image

  3. Assign that rule to your Droplet.

  4. Profit ๐Ÿ’ท

Thanks again for the package and prompt response, it's highly appreciated.

mpratt commented 1 year ago

No problem @johncarter- ! Thanks for the feedback, Im closing this issue. :+1: