Can anyone help me figure out how to extract a Tweet's preview image from its link? I've been using the html-metadata-parser
module to get meta tags, but I'm having trouble finding the image tag for tweets on Twitter. Surprisingly, when I share the link on platforms like Discord, Instagram, and Whatsapp, the tweet's image shows up. How can I extract the preview image link?
require('dotenv').config();
const router = require('express').Router();
const Meta = require('html-metadata-parser');
const axios = require('axios');
const Jimp = require('jimp');
router.post('/webhooks/discounts', async (res, req) => {
const { link, provider, oauth } = req.body;
if (
oauth === process.env.IFTTTOAUTH
) {
var response = await Meta.parser(link);
const metaTags = JSON.stringify(response, null, 3);
let hasImage;
let ProviderNameURL;
await metaTags.og.images[0] ? hasImage = true : hasImage = false;
provider === "Steam" ? ProviderNameURL = "steam" : provider === "Ubisoft" ? ProviderNameURL = "ubisoft" : provider === "EpicGames" ? ProviderNameURL = "epic_games" : provider === "GOG.com" ? ProviderNameURL = "gog_com" : provider === "Humble Bundle" ? ProviderNameURL = "humble_bundle" : "unknown";
const text = await metaTags.og.description;
const image = hasImage === true ? await metaTags.og.images[0].url : null;
const icon = `https://cdn.syfac.xyz/images/game_markets/${ProviderNameURL}.png`;
const urlToDiscount = link;
try {
axios.post(requesterURL, {
text,
image,
provider,
icon,
urlToDiscount,
hasImage,
})
} catch (err) {
console.log(err)
}
} else {return;}
})
module.exports = router;
I'm struggling with extracting the correct image link as the og:image
represents the profile picture, not the tweet image.
Upon examining Twitter's meta tags, I noticed links with preconnect and dns-prefetch leading to //pbs.twimg.com. The image source in Discord embeds also point to pbs.twimg.com, which seems promising. However, I'm still unsure how to retrieve the actual tweet image.