Ibrahim Al-Habian
Ibrahim Al-Habian

Reputation: 13

Show Youtube thumbnail using javascript

    You can not use Markdown in here.
`rhrdshh`

Upvotes: 1

Views: 252

Answers (1)

adampweb
adampweb

Reputation: 1469

You must define og meta tags in your html head for facebook share. Look for official docs: https://developers.facebook.com/docs/sharing/webmasters#markup-example

Meta tags are not modifiable from JS, you must set these elements in server-side (or hard-coded in HTML file), and will not working with redirects. Only work if your embed the video in your site, my php example:

<?php
 $video_id = "1bibCui3lFM";

 $video_url = "https://www.youtube.com/watch?v=" . $video_id;

 $content=file_get_contents("https://noembed.com/embed?url=".$video_url);
 $video_data=json_decode($content);
?>
<!DOCTYPE html>
<html>
<head>
    <title>Youtube Embed Video sample</title>

    <meta property="og:url"                content="<?php echo($_SERVER['QUERY_STRING']); ?>" />
    <meta property="og:type"               content="website" />
    <meta property="og:title"              content="<?php echo($video_data->title) ?>" />
    <meta property="og:description"        content="THIS API IS NOT SUPPORT TO GET VIDEO DESCRIPTION" />
    <meta property="og:image"              content="<?php echo($video_data->thumbnail_url) ?>" />
</head>
<body>
    <pre><?php var_dump($video_data); ?></pre>

    <iframe width="420" height="315"
        src="https://www.youtube.com/embed/<?php echo($video_id) ?>">
    </iframe>
</body>
</html>

Upvotes: 2

Related Questions