Question

When I am sharing a link in FB, it somehow grabs some key information from that link and builds a sharing block containing images, name, title and the summary of that page.

How do they do that??

Do they go to the page of that link and parse every divs of that page to grad those information???

Was it helpful?

Solution

How do they do that??

Facebook uses a protocol called Open Graph Protocol

Do they go to the page of that link and parse every divs of that page to grad those information???

No, Facebook scrapes your page's OG <meta /> tags from <head> tags and extract the data from them

to install them, you can follow the full documentation at OGP site

basic example

<html prefix="og: http://ogp.me/ns#">
<head>
<title>My awesome article - site</title>
<meta property="og:title" content="My awesome article - site" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://www.site.com/my-awesome-article" />
<meta property="og:image" content="http://www.site.com/images/my-awesome-article.jpg" />
...
</head>
...
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top