How facebook handles hyperlinks in posts?

Discussion in 'Programming' started by pHrEaK, Mar 19, 2013.

  1. #1
    First off let me start by saying I hate using facebook as an example but in this instance it seems as though it would be the clearest way to explain what I'm trying to do...I'm guessing everyone has been on the site and has posted things to their page or news feed?

    If you browse to the site and paste a hyperlink into your "status update" box you will notice that a small loading icon may appear followed by an image, title, and description of that page. I'm assuming this is just metadata contained in the page's (page that hyperlink points to) head section?

    What I would like to know is how facebook is handling the situation when a user pastes (or types in for that matter, how it instantiates is frivolous) a hyperlink into the textbox. What language is being used to handle this request? If a postback was acceptable I'm thinking I could do some cURL magic in php to accomplish the same task, but since the information needs to be pulled back "on the fly" I'm a bit lost since this is more than likely going to be accomplished using a language I'm not accustomed to (I'm guessing ajax possibly?).

    If anyone could point me in the proper direction it would be greatly appreciated. I'm always up for learning new things! :)
     
    pHrEaK, Mar 19, 2013 IP
  2. Endurint

    Endurint Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    1. JavaScript detects a possible URL in the user's post (a regex pattern is run on the change event for the input element). Edit: the way I phrased this was ambiguous. More clear: On the change event of the input element, a regex pattern is run against the element's content/value.

    2. If a URL is detected, then there's an AJAX call to a server-side script that strictly validates the URL format and the postback. This could be any server-side language, but in FB's case it's PHP that's been compiled to C++ via their HipHop compiler.

    3. If the postback is valid, then FB' server side script grabs the page title, some text from the body element, and some available images from the remote URL. Again, this is PHP/HipHop.

    4. The "preview" content is assembled and sent back to the user via an AJAX call, where the user has the ability to choose a thumbnail, etc. (if applicable).

    5. The user hits post, the preview content is finalized, and FB stores the link as a unique, trackable asset in their data mine. What they do with it from there is milk it for data that advertisers might want.
     
    Endurint, Mar 19, 2013 IP
  3. pHrEaK

    pHrEaK Active Member

    Messages:
    147
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Excellent! Thank you for the clarification. You seem to know a bit about how fb goes about it's business :)

    For anyone who might stumble across this post in the future I'm going to post a link below that does a great job about explaining AJAX and breaks an AJAX call down in a rather simplistic fashion.

    http://tech.pro/tutorial/791/simple-ajax-php-and-javascript
     
    pHrEaK, Mar 19, 2013 IP