You are here:
/ Dashboard / Main / FacebookAPI

Facebook client API as UDT

What is it for?

The API gives developers an easy way to communicate with Facebook, handling authentication with transparent communication.

  • Scope of usage: with any VSP or VSPX page (not just ODS)

How to use it?

To use the API you should execute facebook.sql.

Note: In order to take the latest versions of the files, you need to upgrade to the latest version of the ods_framework_dav.vad package.

What should be the expected result?

After execution of the sql file, a type with name "DB.DBA.Facebook" will be created. Creating object of this type with correct parameter will set up function REST client for Facebook.

Description of usage:

  1. 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.
  2. The user and (api key, api secret) are not related. The developer should set just api key and api secret. Essential part of the UDT is its property named "api_client":
    1. This property is of type DB.DBA.FacebookRestClient - a type that is also available after execution of facebook.sql .
    2. 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 your 32-character api key that corresponds to the application you have 
-- created in facebook .
appapikey := '5568c178ad6a4cef74da4848b164602c'; 

-- here you should put you api secret 32chars that corresponds to the application you have 
-- created in facebook site.
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 parameter available in VSP

--With this action the API is set up.

--In order to make user to login to Facebook (we can not communicate to its data 
--without that) we should make him 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 
-- do 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 relate 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 the functions, but auth_getSession(),users_getInfo( uids any,fields any),
-- users_isAppAdded() return XML entitiy as result.

Usage of the Facebook client API as UDT in ODS

Virtuoso and the Virtuoso Website are Copyright (C) OpenLink Software 2006-
SourceForge.net Logo