We are writing a Facebook application

    Facebook is a popular social network where you can write your application. I do not like to crush water in a mortar, so immediately to the point. You can embed in two directions : an external application on Facebook or Facebook data in an external application (aka Facebook Connect ). Here I will talk about the first, which in principle is more time-consuming and interesting. As a rule, the meaning of a facebook application has two functions - interaction with friends and informative integration into the user profile.

    The basics


    You can embed the application in the following places ..
    • Canvas - the actual page with the application. Available at apps.facebook.com/ PROGRAM TITLE
    • Profile box - a small box inside the user profile itself
    • Profile tab - a new tab in the profile
    • Boxes tab - a small block in the tabs boxes
    • News feed - access to the stream of updates
    • Requests box - interactive messages to other users

    Integration is done by mixed capabilities ..
    • REST API (http://api.new.facebook.com/restserver.php) which provides “hard” access for the backend with the ability to upload photos, videos, receive friends lists, events, comments, etc.
    • FQL - a way to request REST data not just through method parameters, but already through SQL-like syntax
    • FBML - truncated HTML + its tags that Facebook interprets in a window in its own style and design and caches when displayed inline. A bunch of troubles with a built-in tag validator
    • xFBML - FBML tags used in your application
    • FBJS - Truncated JS

    Two ways


    Now that the basic terms are clear, let's move on to the application itself, which is hosted in Canvas. After creating a new application through the developer app , downloading the REST library for php, putting the application on your website and installing it in the URL settings for Canvas, you can see that there are two ways to launch it - through iframe (+ XFBML) or pure FBML that will be stored on facebook. Of course, the first option is the simplest. After creating the program and adding / confirming in your profile, the Canvas display will be accompanied by the usual iframe + GET parameters with the prefix fb_sig_, of which the most important is fb_sig_canvas_user. The second option is more dreary, but more closely related to FB.




    Rights


    Now we need to think about what the application does in principle. In my case, this is a quiz test - the user answers questions and at the end the status is put on the profile wall.
    First of all, it turns out that it is very useful to have user confirmation for receiving data ( Authorization ), which is called by the
    Facebook :: require_login method and for the user looks just like a window for
    transferring rights. Having rummaged in the documentation for publishing data in the Wall (News feed), there is the Feed.publishTemplatizedAction method , but it turned out to be deprecated. The alternative is Stream.publish , and now we move on to the second important topic - Extended permissions .


    Without rights, the request will receive a fatal error. In order for the program to get deeper access over the
    user profile , the latter must confirm this separately in the dialog
    box. And calling this dialog to post a message on the wall or
    changing the status of the user is not so simple.
    $facebook->api_client->stream_publish("My new status");
    Uncaught exception 'FacebookRestClientException' with message 'The user hasn't authorized the application to perform this action' i
    Now a little subtlety - the documentation in the wiki and on the forums should be read with great suspicion, because
    outdated code is often found (for example, the names of the privileges / methods stream_publish instead of
    publish_stream). Methods for checking privileges give either a fatal error or an unintelligible unsubscription for parameters, including the test API console
    if($facebook->api_client->users_hasAppPermission("publish_stream")){
    //обновить статус тут
    }


    FBML Temptation


    By this time, the advantages of the FBML mode (forcing a similar interface and the supported FBML tags) become clear. It worked for me
    • FBML mode + onclick + tagHeelp
    • FBML mode +
      + onclick

    • Iframe + redirect to www.facebook.com/authorize.php?api_key= MY_API_KEY&v=1.0&ext_perm=publish_stream&next=http: //google.com

      Although it looks very buggy: FBML mode + redirect gave an “Error while loading page” message


    xFBML


    It is clear that the rights to receive through the iframe in this way are buggy, I want to live together separately and on facebook at the same time. For this, there are xFBML tags that are interpreted by Facebook javascript. Total you need in your application you need:
    1. Connect javascript static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php
    2. Make xd_receiver.htm
    3. Initialize with your api-key
    4. Specify the path to the root in the settings of the Connect application on Facebook

    Now you can ask for rights

    FB.Connect.showPermissionDialog('publish_stream');

    The Lost Cookie Donkey


    You can’t get around without mentioning IE 6/7 here. The fact is that by default the iframe in these browsers loses session variables. Simply put, cookies do not reach the server because the iframe is considered to be “unreliable” content and it even shows an eye in its status bar. If you understand this in detail , then there is a justification for this in the form of the W3C platform for privacy preferences . To do this, add a title easier
    header('P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); //for IE6/7
    in the end application is successfully updated the profile (which managed to push through and picture attachments) Original

    Hiller



    Also popular now: