sur950 / any_link_preview

A flutter Plugin/Package to show the preview of any web link that starts with HTTP/HTTPS. Mostly useful for application that had chat.
MIT License
72 stars 72 forks source link

Preview function aren't working with Twitter URL #72

Open mostafasany opened 4 months ago

mostafasany commented 4 months ago

I'm trying to open Twitter preview but it doesn't work.

My code

AnyLinkPreview( link: "https://x.com/mahmoudanwar74/status/1802647958149632408", ) I can view the preview correctly on other sites, but this link does not show the preview.

Please advise!

harshit-kishor2 commented 2 months ago

@mostafasany I don't know the reason, but I have checked with 'https://x.com/mahmoudanwar74/status/1802647958149632408/' and it shows a preview. Adding a slash at the end of the URL fixes the issue.

mostafasany commented 2 months ago

@harshit-kishor2 I tried adding slash at the end of the URL but it doesn't help

harshit-kishor2 commented 2 months ago

@mostafasany Here is the response ~ A. With slash - {title: مۭــحۡــمۭــۏد انوُرٍ Mahmoud Anwar (@mahmoudanwar74) on X, description: بلسان لبيب اهو النادى عايش على فلوس #تركى_ال_شيخ يا شوية شحاتين ومتسؤلين يا مهزقيين اسمعوا رئيسكم بيقول ايه يا افقين يا مدلسيين, image: https://pbs.twimg.com/ext_tw_video_thumb/1802596459545575424/pu/img/T8TJSo2OkjQB6pGp.jpg:large, url: https://x.com/mahmoudanwar74/status/1802647958149632408, timeout: 1723195918}

b. Without slash {title: x.com, description: null, image: null, url: https://x.com/mahmoudanwar74/status/1802647958149632408, timeout: 1723183279}

Here is my fetching method- Metadata? metadata = await AnyLinkPreview.getMetadata( link: 'your_url', cache: const Duration(days: 7), );

harshit-kishor2 commented 2 months ago

Well I'm stuck with this url- https://www.viator.com/blog/First-Timers-Guide-to-London/l29233 Here i'm getting null.

harshit-kishor2 commented 2 months ago

Well I'm stuck with this url- https://www.viator.com/blog/First-Timers-Guide-to-London/l29233 Here i'm getting null.

I got solution for my issue- I have used this header property

Metadata? metadata = await AnyLinkPreview.getMetadata( link: getUri, cache: const Duration(days: 7), headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'Referer': 'https://www.google.com/', 'Accept-Language': 'en-US,en;q=0.9', 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8', 'Connection': 'keep-alive', } );

mostafasany commented 2 months ago

@harshit-kishor2 Using the bellow code return Metadata but has empty image

link = 'https://x.com/mahmoudanwar74/status/1802647958149632408/';
    Metadata? metadata = await AnyLinkPreview.getMetadata(
        link: link,
        cache: const Duration(days: 7),
       );

When you verify if it working or not, check the Metdata.Image, because checking only metadata if its null or not is not enough