开发者

How does Facebook pull website data when it sees you've typed a URL into a wall post?

So I'm writing a post on my wall and type a URL into the main body of the post. As soon as I finish the URL, Facebook creates a little section underneath which has the title,开发者_JAVA百科 description, and an image from the url I typed.

Without getting too indepth, how is this done and what is the best way of make something similar myself?


jQuery (or some other framework that lets you do Ajax easily) to communicate between browser client and webserver

PHP/ASP.NET/Python (or some other scripting framework on the backend) to fetch the url

Facebook also has a meta data specification you might be interested in, to let developers further define what gets shown in a Facebook page.


I believe Facebook is written in PHP. And PHP does this easily.

FOpen can be used to access files on other sites. There are other functions but this will get you started. Then it's a matter of parsing the html you get from the url to get what you want.

http://php.net/manual/en/function.fopen.php


You have a couple choices. You can fetch it using Ajax from the client; or you can fetch it from your server.

If doing it from your server in asp.net then you need to use HttpWebRequest.


FB does an asynchronous JavaScript call to fetch that data without reloading the window you're on. Lookup ajax and libraries like jquery do this: http://api.jquery.com/category/ajax/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜