Hello everyone,
I am trying to find out how facebook extract information like image, title and description of a webpage using open graph tags.
Please share you knowledge or any working scripts, tutorial.
Thanks
Hello everyone,
I am trying to find out how facebook extract information like image, title and description of a webpage using open graph tags.
Please share you knowledge or any working scripts, tutorial.
Thanks
Have you any knowledge of parsing an html document with PHP or should we started it by that? If you don’t, have you tried parsing an html document, and if you did , what was the problem of extracting og tags?
Hi,
Facebook does it like this.., and here is an example of an open graph if I am going to write it for Daniweb.com . Warning image url is an assumed location.
<meta property="og:title" content="Your Own Open Graph Meta Application"/>
<meta property="og:image" content="http://daniweb.com/images/daniweb_logo.jpg"/>
<meta property="og:site_name" content="Daniweb"/>
<meta property="og:description" content="An online discussion community of IT professionals. Forums to get free computer help and support."/>
To parse it, look for my previous post about 5 days back... I wrote an example on how to handle meta tags parsing..
Here are the codes I used, but you still need to read my instructions from my previous post, and adjust the url to your application... This can also work outbound and inbound through $_GET..
$url = 'http://watch32.com/movies-online/return-to-the-blue-lagoon-2766';
$file = useCurl($url);
$html = str_get_html($file);
foreach($html->find('meta[name=keywords]') as $element){
echo $element->content.'<br/>';
}
echo '<br/>';
foreach( $html->find('meta[name=description]') as $desc)
$movie_detail = explode("|", $desc->content);
echo 'Title : '. $movie_detail[2].'<br/>';
echo 'Director :'. $movie_detail[3].'<br/>';
$casts= explode(",", $movie_detail[4]);
echo 'Casts<br/>';
foreach($casts as $actor){
echo $actor.'<br/>';
}
function useCurl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)');
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);curl_close($ch);
return $output;
unset($output);
}
This little piece of code shown below,
foreach($html->find('meta[name=keywords]')
Should be change to
foreach($html->find('meta[property]')
Then just iterate the array, and finally grab the result by defining which index you need.. for example
foreach($html->find('meta[property=title]')
Should give you **Your Own Open Graph Meta Application **
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.