I try to get the thumbnail-url from og:image from a twitter post url. For example:
https://twitter.com/cmorehockey/status/1568623857824677888
I can see that there is a url to the thumbnail picture when i inspect in the browser.
I have this code
$url ="https://twitter.com/cmorehockey/status/1568623857824677888";
$sites_html = file_get_contents($url);
$html = new DOMDocument();
@$html->loadHTML($sites_html);
$meta_og_img = null;
//Get all meta tags and loop through them.
foreach($html->getElementsByTagName('meta') as $meta) {
//If the property attribute of the meta tag is og:image
if($meta->getAttribute('property')=='og:image'){
//Assign the value from content attribute to $meta_og_img
$meta_og_img = $meta->getAttribute('content');
}
if($meta->getAttribute('property')=='og:description'){
//Assign the value from content attribute to $meta_og_img
$meta_og_text = $meta->getAttribute('content');
}
}
Dont get any error message, but the $meta_og_img is empty.
Someone know what i do wrong?