PHP - Get Meta Information by EmbedURL - metadata

How I will get meta information specified by EmbedURL? I have tried get_meta_tags('raw_html'). But it returns nothing.
MY HTML:
<!--Video 1-->
<div class="embed-responsive-item" itemprop="video" itemscope="" itemtype="http://schema.org/VideoObject">
<video class="embed-responsive-item" controls="" loop="">
<source src="INTERNAL_VIDEO_URL">
</video>
<meta itemprop="name" content="">
<meta itemprop="duration" content="">
<meta itemprop="thumbnailUrl" content="THUMBNAIL_URL">
<meta itemprop="embedURL" content="INTERNAL_VIDEO_URL">
<meta itemprop="uploadDate" content="2021-03-27T04:10:1600Z">
</div>
<!--Video 2-->
<div class="embed-responsive embed-responsive-16by9" onclick="loadYoutubeVideoThroughYTApi(this)" data-src-id="player-1" data-yut-var="YOUTUBE_VIDEO_ID">
<meta itemprop="description" content="META_DESCRIPTION_2">
<meta itemprop="duration" content="PT1M13S">
<meta itemprop="name" content="META_TITLE_2">
<meta itemprop="thumbnailUrl" content="https://i.ytimg.com/vi/YOUTUBE_VIDEO_ID/maxresdefault.jpg">
<meta itemprop="embedURL" content="https://www.youtube.com/embed/YOUTUBE_VIDEO_ID">
<meta itemprop="uploadDate" content="2019-02-04T11:00:43.000Z">
</div>
<!--Video 3-->
<div class="embed-responsive-item" itemprop="video" itemscope="" itemtype="http://schema.org/VideoObject">
<video class="embed-responsive-item" controls="" loop="">
<source src="INTERNAL_VIDEO_URL_2">
</video>
<meta itemprop="name" content="">
<meta itemprop="duration" content="">
<meta itemprop="thumbnailUrl" content="THUMBNAIL_URL_2">
<meta itemprop="embedURL" content="INTERNAL_VIDEO_URL_2">
<meta itemprop="uploadDate" content="2021-03-27T04:10:1600Z">
</div>
As you can see the html contains three different videos with three different meta properties. So the result array should be look like this
Desired Output:
Array
(
[0] => Array
(
[url] => INTERNAL_VIDEO_URL
[meta_name] => NULL
[meta_description] => NULL // as you can see no meta tags for description
[meta_duration] => NULL
[meta_thumbnail] => THUMBNAIL_IMAGE_URL
[upload_date] => 2021-03-27T04:10:1600Z
)
[1] => Array
(
[url] => https://www.youtube.com/embed/YOUTUBE_VIDEO_ID
[meta_name] => META_TITLE_2
[meta_description] => META_DESCRIPTION_2
[meta_duration] => PT1M13S
[meta_thumbnail] => https://i.ytimg.com/vi/YOUTUBE_VIDEO_ID/maxresdefault.jpg
[upload_date] => 2021-03-27T04:10:1600Z
)
[2] => Array
(
[url] => INTERNAL_VIDEO_URL_2
[meta_name] => NULL
[meta_description] => NULL // as you can see no meta tags for description
[meta_duration] => NULL
[meta_thumbnail] => THUMBNAIL_IMAGE_URL_2
[upload_date] => 2021-03-27T04:10:1600Z
)
)
How will I get the set of array like this?

Related

PHP - Get Meta Information by EmbedURL

How I will get meta information specified by EmbedURL? I have tried get_meta_tags('MY_VIDEO_URL'). But it returns nothing.
MY HTML:
<!--Video 1-->
<div class="embed-responsive-item" itemprop="video" itemscope="" itemtype="http://schema.org/VideoObject">
<video class="embed-responsive-item" controls="" loop="">
<source src="INTERNAL_VIDEO_URL">
</video>
<meta itemprop="name" content="">
<meta itemprop="duration" content="">
<meta itemprop="thumbnailUrl" content="THUMBNAIL_URL">
<meta itemprop="embedURL" content="INTERNAL_VIDEO_URL">
<meta itemprop="uploadDate" content="2021-03-27T04:10:1600Z">
</div>
<!--Video 2-->
<div class="embed-responsive embed-responsive-16by9" onclick="loadYoutubeVideoThroughYTApi(this)" data-src-id="player-1" data-yut-var="YOUTUBE_VIDEO_ID">
<meta itemprop="description" content="META_DESCRIPTION_2">
<meta itemprop="duration" content="PT1M13S">
<meta itemprop="name" content="META_TITLE_2">
<meta itemprop="thumbnailUrl" content="https://i.ytimg.com/vi/YOUTUBE_VIDEO_ID/maxresdefault.jpg">
<meta itemprop="embedURL" content="https://www.youtube.com/embed/YOUTUBE_VIDEO_ID">
<meta itemprop="uploadDate" content="2019-02-04T11:00:43.000Z">
</div>
<!--Video 3-->
<div class="embed-responsive-item" itemprop="video" itemscope="" itemtype="http://schema.org/VideoObject">
<video class="embed-responsive-item" controls="" loop="">
<source src="INTERNAL_VIDEO_URL_2">
</video>
<meta itemprop="name" content="">
<meta itemprop="duration" content="">
<meta itemprop="thumbnailUrl" content="THUMBNAIL_URL_2">
<meta itemprop="embedURL" content="INTERNAL_VIDEO_URL_2">
<meta itemprop="uploadDate" content="2021-03-27T04:10:1600Z">
</div>
As you can see the html contains three different videos with three different meta properties. So the result array should be look like this
Desired Output:
Array
(
[0] => Array
(
[url] => INTERNAL_VIDEO_URL
[meta_name] => NULL
[meta_description] => NULL // as you can see no meta tags for description
[meta_duration] => NULL
[meta_thumbnail] => THUMBNAIL_IMAGE_URL
[upload_date] => 2021-03-27T04:10:1600Z
)
[1] => Array
(
[url] => https://www.youtube.com/embed/YOUTUBE_VIDEO_ID
[meta_name] => META_TITLE_2
[meta_description] => META_DESCRIPTION_2
[meta_duration] => PT1M13S
[meta_thumbnail] => https://i.ytimg.com/vi/YOUTUBE_VIDEO_ID/maxresdefault.jpg
[upload_date] => 2021-03-27T04:10:1600Z
)
[2] => Array
(
[url] => INTERNAL_VIDEO_URL_2
[meta_name] => NULL
[meta_description] => NULL // as you can see no meta tags for description
[meta_duration] => NULL
[meta_thumbnail] => THUMBNAIL_IMAGE_URL_2
[upload_date] => 2021-03-27T04:10:1600Z
)
)
How will I get the set of array like this?
After so many research I have come up with a solution that gives my desired output.
<?php
function load_my_custom_attributes_from_meta_tags( $string )
{
$htmlDom = new DOMDocument();
$errorBuffer = libxml_use_internal_errors( true );
$htmlDom->loadHTML($string);
libxml_clear_errors();
libxml_use_internal_errors( $errorBuffer );
$result = Array(
"url" => NULL,
"meta_name" => NULL,
"meta_description" => NULL,
"meta_duration" => NULL,
"meta_thumbnail" => NULL,
"upload_date" => NULL
);
$arrayKeyMap = Array(
"embedURL"=>"url",
"name"=>"meta_name",
"description"=>"meta_description",
"thumbnailURL"=>"meta_thumbnail",
"duration"=>"meta_duration",
"uploadDate"=>"upload_date"
);
$main_array = array();
foreach ($htmlDom->getElementsByTagName("meta") as $tag) {
$temp = Array();
foreach ( $tag->attributes as $attribute ) {
$temp[ $attribute->nodeName ] = $attribute->nodeValue;
}
if ( array_key_exists( "itemprop" , $temp ) && array_key_exists( "content" , $temp ) && array_key_exists( $temp["itemprop"] , $arrayKeyMap ) ) {
$result[ $arrayKeyMap[ $temp["itemprop"] ] ] = $temp["content"] === "" ? NULL : $temp["content"];
}
}
return $result;
}
$file_contents = file_get_contents('PAGE_URL');
preg_match_all('/<div class=\"embed-responsive\">(.*?)<\/div>/s',$file_contents,$matches);
$all_meta_properties = $matches[0];
$meta_array = array();
foreach($all_meta_properties as $video_meta) {
$meta_array[] = load_my_custom_attributes_from_meta_tags($video_meta);
}
print_r($meta_array);
?>

Facebook Open Graph og:image exists but is invisible

I'm using the Open Graph Object Debugger to test this link: http://ayconatest.co.nf/?p=1957, and all the properties are there including the image, except it's invisible. You can click on it and see it, but it doesn't show up, even though the dimensions are 500x375 px. What's up with that?
Here's my header code:
<?php if (have_posts()):while(have_posts()):the_post(); endwhile; endif;?>
<!-- the default values -->
<meta property="fb:app_id" content="271801723026128" />
<meta property="fb:admins" content="779283165" />
<!-- if page is content page -->
<?php if (is_single()) { ?>
<meta property="og:url" content="<?php the_permalink() ?>"/>
<meta property="og:title" content="<?php single_post_title(''); ?>" />
<meta property="og:description" content="<?php echo strip_tags(get_the_excerpt($post->ID)); ?>" />
<meta property="og:type" content="article" />
<meta property="og:image" content="<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 500,375 ) ); echo $src[0]; ?>" />
<!-- if page is others -->
<?php } else { ?>
<meta property="og:site_name" content="<?php bloginfo('name'); ?>" />
<meta property="og:description" content="<?php bloginfo('description'); ?>" />
<meta property="og:type" content="website" />
<meta property="og:image" content="http://ayconatest.co.nf/wp-content/themes/imbalance2/images/logo.png" /> <?php } ?>
And here's what it returns (Ctrl + U):
<!-- the default values -->
<meta property="fb:app_id" content="271801723026128" />
<meta property="fb:admins" content="779283165" />
<!-- if page is content page -->
<meta property="og:url" content="http://ayconatest.co.nf/?p=1957"/>
<meta property="og:title" content="النباتات تستطيع القيام بعمليات GoPro لاقتصاد الطاقة" />
<meta property="og:description" content="كلما أثيرت مسألة للنقاش في الساحة الوطنية حول ما يتصل بالهوية الحضارية للشعب المغربي إلا ووجدت تيارين متقابلين يتجاذبان الموضوع ويعبران عن رؤيتين متضادتين, أو مايصطلح عليه Statu-quo وهذا أمر طبيعي، وطبيعي كذلك أن يكون أحد الرأيين وأحدهما فقط صائبا ما" />
<meta property="og:type" content="article" />
<meta property="og:image" content="http://ayconatest.co.nf/wp-content/uploads/2013/06/plantsthumb.jpg" />
<!-- if page is others -->
Incidentally, the debugger detects and shows any other picture that is hotlinked from another website. This leads me to think there's something wrong with my hosting, or maybe my folder structure? but I don't know what exactly.
The URLs used as the og:image in your examples doesn't exist / work:
I checked them both - and the screenshot below is of what happens when I try to reach the second example, http://ayconatest.co.nf/wp-content/uploads/2013/06/plantsthumb.jpg
Ensure the value you set for og:image is accessible externally and that should fix your issue

Post swf with parameters to facebook via application

I have a facebook application where the user choose 4 of his friends and then it creates a video (swf) with the pictures of your friends in it (loaded via xml). So I need to share this video on the user timeline. Everything works fine but the video is not embedded in the post on his timeline, there is only a post with the link to the page in it.
The weird thing is, if I post the url directly on my timeline, the video is embedded, but not if the same link is posted via the application.
here is my code called by the share button in js :
function postToFeed() {
var obj = {
method: 'feed',
link: 'https://mysite.com/flash/share-page.php?id=22',
picture: 'https://mysite.com/images/video-preview.jpg',
name: 'Name',
caption: 'Caption',
description: 'Description'
};
function callback(response) {
//some code here
}
FB.ui(obj, callback);
}
and the code in my share-page.php
<?php
$id_inscription = $_GET['id'];
$video_url = 'https://mysite.com/flash/share-page.php?id=22';
$video_preview_image = 'https://mysite.com/images/video-preview.jpg';
?>
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-language" content="en">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta property="og:video" content="<?php echo $video_url; ?>"/>
<!-- Open grah tags for Facebook -->
<meta property="og:title" content="Test video player" />
<meta property="og:description" content="A video player interface experiment." />
<meta property="og:type" content="video" />
<meta property="og:url" content="<?php echo $video_url; ?>"/>
<meta property="og:image" content="<?php echo $video_preview_image; ?>"/>
<meta property="og:site_name" content="Site name"/>
<!-- Video specific open graph tags -->
<meta property="og:video" content="<?php echo $video_url; ?>" />
<meta property="og:video:secure_url" content="<?php echo $video_url; ?>" /> <!-- Required for people on Facebook who have secure browsing enabled! -->
<meta property="og:video:width" content="325" />
<meta property="og:video:height" content="180" />
<meta property="og:video:type" content="application/x-shockwave-flash" />
<script src="js/swfobject.js"></script>
<script>
var flashvars = {
xmlUrl:"xml/data-<?php echo $id_inscription; ?>.xml",
policyFileUrl:"http://profile.ak.fbcdn.net/crossdomain.xml"
};
var params = {
menu: "false",
scale: "noScale",
allowFullscreen: "true",
allowScriptAccess: "always",
bgcolor: "",
wmode: "opaque"
//wmode: "direct" // can cause issues with FP settings & webcam
};
var attributes = {
id:"content"
};
swfobject.embedSWF(
"app.swf",
"altContent", "480", "270", "10.0.0",
"expressInstall.swf",
flashvars, params, attributes);
</script>
</head>
<body>
<div id="altContent">
<p>Get Adobe Flash player</p>
</div>
</body>
</html>
Found it, in the javascript you have to add
source: 'https://mysite.com/flash/app.swf'
DOesnt work for me .
Also facebook says ,It is NOT supposed to work By Design .
https://developers.facebook.com/bugs/589975484398226?browse=external_tasks_search_results_526fc388b99e18881434478
Please share here your code snippet if you could make it work . I have the meta tags taking care for the secure video Url as well .

Facebook Meta Tags

My problem was when some one is liking my website, the image, description, title etc. where completly wrong it took the first which is the service level agreement in my website. So I figured I have to add opengraph meta tags so I did:
<meta property="og:url" content="http://url.com/" />
<meta property="og:site_name" content="My Web" />
<meta property="og:type" content="website" />
<meta property="og:title" content="My Web.com" />
<meta property="og:image" content="http://url.com/logo.png" />
<meta property="og:description" content="My Web is a new community" />
<meta property="fb:app_id" content="7363627862327638" />
The problem is, it is still not working, the likes information is wrong, and I waited atleast 72 hours, so the cache of Facebook is not the problem.
Does anyone know what could be the problem? Thanks alot already!
Checkout this.. tutorial.
and use facebook debug tool to clear cache and set new metatags for your page.
Try this it worked for me -
Use Dynamic content in meta tag.
<?php
$params = array();
if(count($_GET) > 0) {
$params = $_GET;
} else {
$params = $_POST;
}
// defaults
if($params['type'] == "") $params['type'] = "restaurant";
if($params['locale'] == "") $params['locale'] = "en_US";
if($params['title'] == "") $params['title'] = "default title";
if($params['image'] == "") $params['image'] = "thumb";
if($params['description'] == "") $params['description'] = "default description";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# MY_APP_NAME_SPACE: http://ogp.me/ns/fb/MY_APP_NAME_SPACE#">
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<!-- Open Graph meta tags -->
<meta property="fb:app_id" content="MY_APP_ID" />
<meta property="og:site_name" content="meta site name"/>
<meta property="og:url" content="URL?type=<?php echo $params['type']; ?>&locale=<?php echo $params['locale']; ?>&title=<?php echo $params['title']; ?>&image=<?php echo $params['image']; ?>&description=<?php echo $params['description']; ?>"/>
<meta property="og:type" content="MY_APP_NAME_SPACE:<?php echo $params['type']; ?>"/>
<meta property="og:locale" content="<?php echo $params['locale']; ?>"/>
<meta property="og:title" content="<?php echo $params['title']; ?>"/>
<meta property="og:image" content="URL<?php echo $params['image']; ?>.png"/>
<meta property="og:description" content="<?php echo $params['description']; ?>"/>
</head>
</html>

any ideas why facebook like button do not display non-English letters on a wordpress blog?

All non-English (Lithuanian) elements like š,ė,ž,č and more are displayed as code which doesnt look nice. I added a facebook like button to my wordpress blog, which looks like this:
<iframe src="http://www.facebook.com/plugins/like.php?locale=lt_LT&href=<?php echo urlencode(get_permalink($post->ID)); ?>&layout=standard&show_faces=false&width=450&action=like&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; position: relative; top: -150px; padding: 0 0 20px 0; overflow:hidden; width:450px; height:60px"></iframe>
You can see that I added locale=lt_LT (I'm from Lithuania)
DOCTYPE:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Im using this:
<?php
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
$default_img = get_bloginfo('stylesheet_directory').'/images/default_icon.jpg';
?>
<?php if(is_single() || is_page()) { ?>
<meta property="og:type" content="article" />
<meta property="og:title" content="<?php single_post_title(''); ?>" />
<meta property="og:description" content="<?php
while(have_posts()):the_post();
$out_excerpt = str_replace(array("\r\n", "\r", "\n"), "", get_the_excerpt());
echo apply_filters('the_excerpt_rss', $out_excerpt);
endwhile; ?>" />
<meta property="og:url" content="<?php the_permalink(); ?>"/>
<meta property="og:image" content="<?php if ( $thumb[0] == null ) { echo $default_img; } else { echo $thumb; } ?>" />
<?php } else { ?>
<meta property="og:type" content="article" />
<meta property="og:title" content="<?php bloginfo('name'); ?>" />
<meta property="og:url" content="<?php bloginfo('url'); ?>"/>
<meta property="og:description" content="<?php bloginfo('description'); ?>" />
<meta property="og:image" content="<?php if ( $thumb[0] == null ) { echo $default_img; } else { echo $thumb; } ?>" />
<?php } ?>
Can it be a problem with DOCTYPE or something else?
The language of the button sets when you order a button from http://developers.facebook.com/docs/reference/plugins/like/
the button should have the language according to the user. example
js.src = "/ / connect.facebook.net / es_LA / all.js # xfbml = 1 & appId = 250867014982684";
that line where it says you can modify for your code es_LA language. This is html 5.
ok, for like button, try using fb developer page and get the code for htlm5; instead of iframe. i made like button in spanish some time ago, let me check my code. i'll get baack to you.