When you type a URL into facebook, it automatically comes up with the "post a link" feature. With most websites, it automatically loads a selection of images it pulls from somewhere in the page to go alongside the link and description. does anyone have an idea of how to implement that same feature for our own site without any FB API etc.. just javascript or JQuery ?
When you plug a URL into this tool, it pre-loads all the information Facebook needs in order to generate a link preview in the future. Facebook stores that info, and then when you get around to actually sharing the link, they're able to generate the preview – even the very first time you share it.
Facebook needs to refresh the link again. In most cases, the data stays unrefreshed for up to 30 days.
Log into Facebook if you're not already with a username and password, visit the Facebook Sharing debugger page, Paste the link, for which the Preview wasn't shown, and click 'Debug'. Ignore the warnings and click 'Scrape Again', now debugger tool will show the link preview at the bottom of the page correctly.
The thumbnail is generated automatically as the Facebook system scans the link for any associated image files. Most links have several image files associated with them, in one way or another, and Facebook won't always select the best one by default.
Due to security restrictions, JavaScript cannot load any page from any server. Facebook actually asks the Facebook servers for information about that page, and the servers in turn query the page to extract the information. You, too, will need a server-side implementation of this.
Aside from that, it's fairly simple: use an HTTP client library for your language of choice to connect to the provided URL, then use an HTML parsing library to extract the title
tag, identify a significant piece of text in the body
tag, and extract the img
tag sources that seem the most appropriate.
Once your server is able to extract information about a page, it's a fairly simple exercise to call it through AJAX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With