VOS.FacebookAPI

  • Topic
  • Discussion
  • VOS.FacebookAPI(Last) -- DAVWikiAdmin? , 2017-06-29 07:34:50 Edit WebDAV System Administrator 2017-06-29 07:34:50

    Facebook Client API as User Defined Type (UDT)

    What is it for?

    The API gives developers an easy way to communicate with Facebook, handling authentication with transparent communication. It may be used with any VSP or VSPX page, not just ODS.

    How to use it?

    To use the API, you should execute facebook.sql.

    Note: Be sure to get the latest versions of all files, by upgrading to the latest version of the ods_framework_dav.vad package.

    What is the expected result?

    After execution of the SQL file, a type with name "DB.DBA.Facebook" will be created. Creating an object of this type with the correct parameter(s) will set up a functional REST client for Facebook.

    Description of usage:

    • The DB.DBA.Facebook type consists of a main object containing all the properties (api_key, api_secret) required to establish a connection to Facebook and user that is currently logged in to Facebook.
    • The Facebook user has no interaction with (api_key, api_secret). The developer must set api_key and api_secret. Essential part of the UDT is its property named "api_client" —
      • This property is of type DB.DBA.FacebookRestClient, also made available after execution of facebook.sql.
      • This property is the real REST client that takes care of authentication and communication to Facebook.

    Examples

    The most appropriate code example is index.vsp. Here is an annotated short code snippet:


    DECLARE  appapikey, appsecret   VARCHAR;
    DECLARE  _facebook              DB.DBA.Facebook;
    DECLARE  _user                  INTEGER;
    
    -- here you should put the 32-character API key that corresponds to the application you have 
    -- created in Facebook .
    appapikey := '5568c178ad6a4cef74da4848b164602c'; 
    
    -- here you should put the 32-character API secret that corresponds to the application you have 
    -- created in Facebook.
    appsecret := 'f35a624a0c9d153a6fa712a439bea14b'; 
    
    _facebook := new Facebook(appapikey, appsecret, params, lines);
    
    -- Constructor method for the UDT should contain 4 obligatory parameters -  
    -- API key, API secret, params, and lines parameters available in VSP
    
    -- With this action the API is set up.
    
    -- To work with Facebook data, we must make the Facebook user login
    
    _user := _facebook.require_login();
    
    -- after successful login, _user is INTEGER that contains Facebook user ID.
    
    -- All further communication to Facebook is related to api_client property:
    
    -- for example if we want to take full name of current user:
    
    DECLARE _xmle ANY;
    
    _xmle:=_facebook.api_client.users_getInfo(CAST(_user AS VARCHAR),'name');
    
    -- Here we cast _user as VARCHAR, as the first parameter is comma-separated list of 
    -- the users IDs for which we need the field "name". On successful execution, _xmle 
    -- will contain xml entity with the result. We should parse it in order to get what 
    -- we need from result. For example, if we need name as VARCHAR we can 
    -- perform the following:
    
    DECLARE _uname VARCHAR;
    _uname:=CAST(xpath_eval('/users_getInfo_response/user/name', _res) AS VARCHAR);
    
       METHOD auth_getSession
          (
            auth_token    ANY 
          ) 
          RETURNS         ANY,
       METHOD users_getInfo
          (
            uids          ANY, 
            fields        ANY 
          ) 
          RETURNS         ANY,
       METHOD users_isAppAdded
          () 
          RETURNS         ANY,
       METHOD friends_areFriends
          (
            uids1         ANY, 
            uids2         ANY 
          ) 
          RETURNS         ANY,
       METHOD friends_get
          () 
          RETURNS         ANY,
       METHOD events_get
          (
            uid           INTEGER, 
            eids          ANY,
            start_time    INTEGER,
            end_time      INTEGER,
            rsvp_status   VARCHAR 
          ) 
          RETURNS         ANY,
       METHOD events_get
          (
            uid           INTEGER 
          ) 
          RETURNS         ANY,
       METHOD events_getMembers
          (
            eid           INTEGER 
          ) 
          RETURNS         ANY,
       METHOD fql_query
          (
            _query        VARCHAR 
          ) 
          RETURNS         ANY,
       METHOD feed_publishStoryToUser
          (
            title         VARCHAR,
            body          VARCHAR,
            image_1       VARCHAR,
            image_1_link  VARCHAR,
            image_2       VARCHAR,
            image_2_link  VARCHAR,
            image_3       VARCHAR,
            image_3_link  VARCHAR,
            image_4       VARCHAR,
            image_4_link  VARCHAR,
            priority      INTEGER 
          ) 
          RETURNS         ANY,
       METHOD feed_publishStoryToUser
          (
            title         VARCHAR,
            body          VARCHAR
          ) 
          RETURNS         ANY,
       METHOD feed_publishActionOfUser
          (
            title         VARCHAR,
            body          VARCHAR,
            image_1       VARCHAR,
            image_1_link  VARCHAR,
            image_2       VARCHAR,
            image_2_link  VARCHAR,
            image_3       VARCHAR,
            image_3_link  VARCHAR,
            image_4       VARCHAR,
            image_4_link  VARCHAR,
            priority      INTEGER
          ) 
          RETURNS         ANY,
       METHOD feed_publishActionOfUser
          (
            title         VARCHAR,
            body          VARCHAR 
          ) 
          RETURNS         ANY,
       METHOD friends_getAppUsers
          () 
          RETURNS         ANY,
       METHOD groups_get
          (
            uid           INTEGER, 
            gids          ANY
          ) 
          RETURNS         ANY,
       METHOD groups_getMembers
          (
            gid           INTEGER 
          ) 
          RETURNS         ANY,
       METHOD notifications_get
          () 
          RETURNS         ANY,
       METHOD notifications_send
          (
            to_ids        ANY,
            notification  VARCHAR,
            email         VARCHAR
          ) 
          RETURNS         ANY,
       METHOD notifications_sendRequest
          (
            to_ids        ANY,
            type          VARCHAR,
            content       VARCHAR,
            image         VARCHAR,
            invite        INTEGER
          ) 
          RETURNS         ANY,
       METHOD photos_get
          (
            subj_id       INTEGER,
            aid           INTEGER,
            pids          ANY
          ) 
          RETURNS         ANY,
       METHOD photos_getAlbums
          (
            uid           INTEGER,
            aids          INTEGER
          ) 
          RETURNS         ANY,
       METHOD photos_getTags
          (
            pids          ANY 
          ) 
          RETURNS         ANY,
       METHOD profile_setFBML
          (
            markup        VARCHAR,
            uid           INTEGER
          ) 
          RETURNS         ANY,
       METHOD profile_getFBML
          (
            uid           INTEGER 
          ) 
          RETURNS         ANY,
       METHOD fbml_refreshImgSrc
          (
            _url          VARCHAR
          ) 
          RETURNS         ANY,
       METHOD fbml_refreshRefUrl
          (
            _url          VARCHAR
          ) 
          RETURNS         ANY,
       METHOD fbml_setRefHandle
          (
            _handle       VARCHAR,
            fbml          VARCHAR 
          ) 
          RETURNS         ANY
    
    -- You can find description for every method at the beginning of the method 
    -- definition in facebook.sql or in http://wiki.developers.facebook.com/index.php/API
    
    -- there are 3 methods that are related to REST communication but not to API function.
       METHOD generate_sig
          (
            params_array ANY, 
            secret VARCHAR
          ) 
          RETURNS VARCHAR,
       METHOD call_method
          (
            method VARCHAR,
            params ANY
          ) 
          RETURNS ANY,
       METHOD post_request
          (
            method VARCHAR,
            params ANY
          ) 
          RETURNS ANY,
    
    -- all functions return XML entity as result, except 
    -- auth_getSession(), 
    -- users_getInfo(uids ANY, fields ANY), and 
    -- users_isAppAdded()
    

    Usage of the Facebook Client API as UDT in ODS

    Usage of this UDT in ODS is covered elsewhere.

    CategoryODS CategoryOpenSource CategoryVirtuoso CategoryHowTo CategoryFacebook? CategoryUDT?